2014-12-28 04:10:54 +00:00
|
|
|
package net.minecraftforge.debug;
|
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.vecmath.AxisAngle4d;
|
|
|
|
import javax.vecmath.Matrix4f;
|
|
|
|
import javax.vecmath.Quat4f;
|
|
|
|
import javax.vecmath.Vector3d;
|
|
|
|
import javax.vecmath.Vector4f;
|
|
|
|
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraft.block.Block;
|
2015-07-28 21:23:34 +00:00
|
|
|
import net.minecraft.block.ITileEntityProvider;
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.properties.IProperty;
|
2015-07-28 21:23:34 +00:00
|
|
|
import net.minecraft.block.properties.PropertyBool;
|
2015-07-21 04:24:02 +00:00
|
|
|
import net.minecraft.block.properties.PropertyDirection;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-07-28 21:23:34 +00:00
|
|
|
import net.minecraft.client.Minecraft;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2015-07-21 04:24:02 +00:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.Item;
|
2016-04-03 07:13:50 +00:00
|
|
|
import net.minecraft.item.ItemBlock;
|
2016-03-05 01:43:41 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-07-28 21:23:34 +00:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-05 01:43:41 +00:00
|
|
|
import net.minecraft.util.EnumHand;
|
2015-11-09 21:03:39 +00:00
|
|
|
import net.minecraft.util.ITickable;
|
2015-07-28 21:23:34 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-03-21 07:23:27 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
import net.minecraft.util.text.TextComponentString;
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
2015-07-28 21:23:34 +00:00
|
|
|
import net.minecraftforge.client.model.IModel;
|
2015-02-04 06:45:23 +00:00
|
|
|
import net.minecraftforge.client.model.ModelLoader;
|
2015-07-28 21:23:34 +00:00
|
|
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraftforge.client.model.b3d.B3DLoader;
|
2015-07-28 21:23:34 +00:00
|
|
|
import net.minecraftforge.client.model.obj.OBJLoader;
|
|
|
|
import net.minecraftforge.client.model.obj.OBJModel;
|
2016-03-21 07:01:30 +00:00
|
|
|
import net.minecraftforge.common.model.TRSRTransformation;
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraftforge.common.property.ExtendedBlockState;
|
|
|
|
import net.minecraftforge.common.property.IExtendedBlockState;
|
|
|
|
import net.minecraftforge.common.property.IUnlistedProperty;
|
2015-07-28 21:23:34 +00:00
|
|
|
import net.minecraftforge.fml.common.FMLLog;
|
2014-12-28 04:10:54 +00:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2015-02-07 05:35:11 +00:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
2014-12-28 04:10:54 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2015-02-07 05:35:11 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Mod(modid = ModelLoaderRegistryDebug.MODID, version = ModelLoaderRegistryDebug.VERSION)
|
2014-12-28 04:10:54 +00:00
|
|
|
public class ModelLoaderRegistryDebug
|
|
|
|
{
|
|
|
|
public static final String MODID = "ForgeDebugModelLoaderRegistry";
|
|
|
|
public static final String VERSION = "1.0";
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void preInit(FMLPreInitializationEvent event)
|
2015-02-07 05:35:11 +00:00
|
|
|
{
|
2016-04-03 07:13:50 +00:00
|
|
|
List<Block> blocks = Lists.newArrayList();
|
|
|
|
blocks.add(CustomModelBlock.instance);
|
|
|
|
blocks.add(OBJTesseractBlock.instance);
|
|
|
|
blocks.add(OBJVertexColoring1.instance);
|
|
|
|
//blocks.add(OBJDirectionEye.instance);
|
|
|
|
blocks.add(OBJVertexColoring2.instance);
|
|
|
|
blocks.add(OBJDirectionBlock.instance);
|
|
|
|
blocks.add(OBJCustomDataBlock.instance);
|
|
|
|
//blocks.add(OBJDynamicEye.instance);
|
|
|
|
for(Block block : blocks)
|
|
|
|
{
|
|
|
|
GameRegistry.register(block);
|
|
|
|
GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
|
|
|
|
}
|
2015-07-28 21:23:34 +00:00
|
|
|
GameRegistry.registerTileEntity(OBJTesseractTileEntity.class, OBJTesseractBlock.name);
|
|
|
|
GameRegistry.registerTileEntity(OBJVertexColoring2TileEntity.class, OBJVertexColoring2.name);
|
2016-03-21 07:23:27 +00:00
|
|
|
//GameRegistry.registerTileEntity(OBJDynamicEyeTileEntity.class, OBJDynamicEye.name);
|
2015-02-07 05:35:11 +00:00
|
|
|
if (event.getSide() == Side.CLIENT)
|
|
|
|
clientPreInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void clientPreInit()
|
2014-12-28 04:10:54 +00:00
|
|
|
{
|
2016-03-21 07:23:27 +00:00
|
|
|
B3DLoader.INSTANCE.addDomain(MODID.toLowerCase());
|
2014-12-28 04:10:54 +00:00
|
|
|
Item item = Item.getItemFromBlock(CustomModelBlock.instance);
|
2015-06-04 15:49:57 +00:00
|
|
|
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + CustomModelBlock.name, "inventory"));
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2016-03-21 07:23:27 +00:00
|
|
|
OBJLoader.INSTANCE.addDomain(MODID.toLowerCase());
|
2015-07-28 21:23:34 +00:00
|
|
|
Item item2 = Item.getItemFromBlock(OBJTesseractBlock.instance);
|
|
|
|
ModelLoader.setCustomModelResourceLocation(item2, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + OBJTesseractBlock.name, "inventory"));
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
Item item3 = Item.getItemFromBlock(OBJVertexColoring1.instance);
|
|
|
|
ModelLoader.setCustomModelResourceLocation(item3, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + OBJVertexColoring1.name, "inventory"));
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2016-03-21 07:23:27 +00:00
|
|
|
//Item item4 = Item.getItemFromBlock(OBJDirectionEye.instance);
|
|
|
|
//ModelLoader.setCustomModelResourceLocation(item4, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + OBJDirectionEye.name, "inventory"));
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
Item item5 = Item.getItemFromBlock(OBJVertexColoring2.instance);
|
|
|
|
ModelLoader.setCustomModelResourceLocation(item5, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + OBJVertexColoring2.name, "inventory"));
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
Item item6 = Item.getItemFromBlock(OBJDirectionBlock.instance);
|
|
|
|
ModelLoader.setCustomModelResourceLocation(item6, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + OBJDirectionBlock.name, "inventory"));
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
Item item7 = Item.getItemFromBlock(OBJCustomDataBlock.instance);
|
|
|
|
ModelLoader.setCustomModelResourceLocation(item7, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + OBJCustomDataBlock.name, "inventory"));
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2016-03-21 07:23:27 +00:00
|
|
|
//Item item8 = Item.getItemFromBlock(OBJDynamicEye.instance);
|
|
|
|
//ModelLoader.setCustomModelResourceLocation(item8, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + OBJDynamicEye.name, "inventory"));
|
2014-12-28 04:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class CustomModelBlock extends Block
|
|
|
|
{
|
2015-07-21 04:24:02 +00:00
|
|
|
public static final PropertyDirection FACING = PropertyDirection.create("facing");
|
2014-12-28 04:10:54 +00:00
|
|
|
public static final CustomModelBlock instance = new CustomModelBlock();
|
|
|
|
public static final String name = "CustomModelBlock";
|
|
|
|
private int counter = 1;
|
2016-03-21 07:23:27 +00:00
|
|
|
public ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[]{FACING}, new IUnlistedProperty[]{B3DLoader.B3DFrameProperty.INSTANCE});
|
2014-12-28 04:10:54 +00:00
|
|
|
|
|
|
|
private CustomModelBlock()
|
|
|
|
{
|
2016-05-18 12:11:56 +00:00
|
|
|
super(Material.IRON);
|
2015-07-21 04:24:02 +00:00
|
|
|
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
|
2016-05-18 12:11:56 +00:00
|
|
|
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
2014-12-28 04:10:54 +00:00
|
|
|
setUnlocalizedName(MODID + ":" + name);
|
2016-04-03 07:13:50 +00:00
|
|
|
setRegistryName(new ResourceLocation(MODID, name));
|
2014-12-28 04:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isOpaqueCube(IBlockState state) { return false; }
|
2014-12-28 04:10:54 +00:00
|
|
|
|
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isFullCube(IBlockState state) { return false; }
|
2014-12-28 04:10:54 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isVisuallyOpaque() { return false; }
|
|
|
|
|
2015-07-21 04:24:02 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
|
|
|
{
|
|
|
|
return this.getDefaultState().withProperty(FACING, getFacingFromEntity(world, pos, placer));
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-21 04:24:02 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta)
|
|
|
|
{
|
|
|
|
return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-21 04:24:02 +00:00
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state)
|
|
|
|
{
|
|
|
|
return ((EnumFacing) state.getValue(FACING)).getIndex();
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2014-12-28 04:10:54 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
2015-07-21 04:24:02 +00:00
|
|
|
//Only return an IExtendedBlockState from this method and createState(), otherwise block placement might break!
|
2015-06-04 15:49:57 +00:00
|
|
|
B3DLoader.B3DState newState = new B3DLoader.B3DState(null, counter);
|
2016-03-21 07:23:27 +00:00
|
|
|
return ((IExtendedBlockState) state).withProperty(B3DLoader.B3DFrameProperty.INSTANCE, newState);
|
2014-12-28 04:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-05 01:43:41 +00:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
|
2014-12-28 04:10:54 +00:00
|
|
|
{
|
|
|
|
if(world.isRemote)
|
|
|
|
{
|
|
|
|
System.out.println("click " + counter);
|
|
|
|
if(player.isSneaking()) counter--;
|
|
|
|
else counter++;
|
|
|
|
//if(counter >= model.getNode().getKeys().size()) counter = 0;
|
|
|
|
world.markBlockRangeForRenderUpdate(pos, pos);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-21 04:24:02 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public BlockStateContainer createBlockState()
|
2015-07-21 04:24:02 +00:00
|
|
|
{
|
2016-03-21 07:23:27 +00:00
|
|
|
return new ExtendedBlockState(this, new IProperty[]{FACING}, new IUnlistedProperty[]{B3DLoader.B3DFrameProperty.INSTANCE});
|
2015-07-21 04:24:02 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-21 04:24:02 +00:00
|
|
|
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
|
|
|
|
{
|
|
|
|
if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
|
|
|
|
{
|
|
|
|
double d0 = entityIn.posY + (double)entityIn.getEyeHeight();
|
|
|
|
|
|
|
|
if (d0 - (double)clickedBlock.getY() > 2.0D)
|
|
|
|
{
|
|
|
|
return EnumFacing.UP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((double)clickedBlock.getY() - d0 > 0.0D)
|
|
|
|
{
|
|
|
|
return EnumFacing.DOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return entityIn.getHorizontalFacing().getOpposite();
|
|
|
|
}
|
2014-12-28 04:10:54 +00:00
|
|
|
}
|
2015-07-28 21:23:34 +00:00
|
|
|
/**
|
|
|
|
* This block is intended to demonstrate how to change the visibility of a group(s)
|
|
|
|
* from within the block's class.
|
|
|
|
* By right clicking on this block the player increments an integer value in the tile entity
|
|
|
|
* for this block, which is then added to a list of strings and passed into the constructor
|
|
|
|
* for OBJState. NOTE: this trick only works if your groups are named '1', '2', '3', etc.,
|
|
|
|
* otherwise they must be added by name.
|
|
|
|
* Holding shift decrements the value in the tile entity.
|
|
|
|
* @author shadekiller666
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class OBJTesseractBlock extends Block implements ITileEntityProvider
|
|
|
|
{
|
|
|
|
public static final OBJTesseractBlock instance = new OBJTesseractBlock();
|
|
|
|
public static final String name = "OBJTesseractBlock";
|
2016-03-21 07:23:27 +00:00
|
|
|
private ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{OBJModel.OBJProperty.INSTANCE});
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
private OBJTesseractBlock()
|
|
|
|
{
|
2016-05-18 12:11:56 +00:00
|
|
|
super(Material.IRON);
|
|
|
|
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
2015-07-28 21:23:34 +00:00
|
|
|
setUnlocalizedName(MODID + ":" + name);
|
2016-04-03 07:13:50 +00:00
|
|
|
setRegistryName(new ResourceLocation(MODID, name));
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World worldIn, int meta)
|
|
|
|
{
|
|
|
|
return new OBJTesseractTileEntity();
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isOpaqueCube(IBlockState state) { return false; }
|
2015-07-28 21:23:34 +00:00
|
|
|
|
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isFullCube(IBlockState state) { return false; }
|
2015-07-28 21:23:34 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isVisuallyOpaque() { return false; }
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
|
|
|
OBJTesseractTileEntity tileEntity = (OBJTesseractTileEntity) world.getTileEntity(pos);
|
|
|
|
OBJModel.OBJState retState = new OBJModel.OBJState(tileEntity == null ? Lists.newArrayList(OBJModel.Group.ALL) : tileEntity.visible, true);
|
2016-03-21 07:23:27 +00:00
|
|
|
return ((IExtendedBlockState) this.state.getBaseState()).withProperty(OBJModel.OBJProperty.INSTANCE, retState);
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-05 01:43:41 +00:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
|
|
|
if (world.getTileEntity(pos) == null) world.setTileEntity(pos, new OBJTesseractTileEntity());
|
|
|
|
OBJTesseractTileEntity tileEntity = (OBJTesseractTileEntity) world.getTileEntity(pos);
|
2016-03-15 22:42:01 +00:00
|
|
|
IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(MODID.toLowerCase() + ":" + "block/tesseract.obj"));
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
if (player.isSneaking())
|
|
|
|
{
|
|
|
|
tileEntity.decrement();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (model != ModelLoaderRegistry.getMissingModel())
|
|
|
|
{
|
|
|
|
tileEntity.setMax(((OBJModel) model).getMatLib().getGroups().keySet().size() - 1);
|
|
|
|
tileEntity.increment();
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
if (world.isRemote)
|
|
|
|
{
|
2016-03-05 01:43:41 +00:00
|
|
|
// wtf
|
|
|
|
//OBJBakedModel objBaked = (OBJBakedModel) Minecraft.getMinecraft().getBlockRendererDispatcher().getModelFromBlockState(state, world, pos);
|
|
|
|
//objBaked.scheduleRebake(); //not necessarily needed for this specific case, but is available
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
|
|
|
world.markBlockRangeForRenderUpdate(pos, pos);
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public boolean hasTileEntity(IBlockState state)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public static class OBJTesseractTileEntity extends TileEntity
|
|
|
|
{
|
|
|
|
private int counter = 1;
|
|
|
|
private int max = 2;
|
|
|
|
public List<String> visible = new ArrayList<String>();
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public OBJTesseractTileEntity()
|
|
|
|
{
|
|
|
|
this.visible.add(OBJModel.Group.ALL);
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public void increment()
|
|
|
|
{
|
|
|
|
if (this.visible.contains(OBJModel.Group.ALL)) this.visible.remove(OBJModel.Group.ALL);
|
|
|
|
if (this.counter == max)
|
|
|
|
{
|
|
|
|
this.counter = 0;
|
|
|
|
this.visible.clear();
|
|
|
|
}
|
|
|
|
this.counter++;
|
|
|
|
this.visible.add(Integer.toString(this.counter));
|
2016-03-01 12:58:03 +00:00
|
|
|
TextComponentString text = new TextComponentString("" + this.counter);
|
2015-07-28 21:23:34 +00:00
|
|
|
if (this.worldObj.isRemote) Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(text);
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public void decrement()
|
|
|
|
{
|
|
|
|
if (this.visible.contains(OBJModel.Group.ALL)) this.visible.remove(OBJModel.Group.ALL);
|
|
|
|
if (this.counter == 1)
|
|
|
|
{
|
|
|
|
this.counter = max + 1;
|
|
|
|
for (int i = 1; i < max; i++) this.visible.add(Integer.toString(i));
|
|
|
|
}
|
|
|
|
this.visible.remove(Integer.toString(this.counter));
|
|
|
|
this.counter--;
|
2016-03-01 12:58:03 +00:00
|
|
|
TextComponentString text = new TextComponentString("" + this.counter);
|
2015-07-28 21:23:34 +00:00
|
|
|
if (this.worldObj.isRemote) Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(text);
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public void reset()
|
|
|
|
{
|
|
|
|
this.counter = 1;
|
|
|
|
this.max = 2;
|
|
|
|
this.visible.clear();
|
|
|
|
this.visible.add(Integer.toString(this.counter));
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public int getMax()
|
|
|
|
{
|
|
|
|
return this.max;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public void setMax(int max)
|
|
|
|
{
|
|
|
|
this.max = max;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public void setToMax()
|
|
|
|
{
|
|
|
|
this.counter = this.max;
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
/**
|
2016-03-01 12:58:03 +00:00
|
|
|
* This block demonstrates how to utilize the vertex coloring feature
|
2015-07-28 21:23:34 +00:00
|
|
|
* of the OBJ loader. See 'vertex_coloring.obj' and 'vertex_coloring.mtl' in
|
|
|
|
* 'test/resources/assets/forgedebugmodelloaderregistry/models/block/', to properly
|
|
|
|
* utilize this feature an obj file must have 1 'usemtl' key before every vertex as shown,
|
|
|
|
* having less 'usemtl' lines than 'v' lines will result in the faces having that material's
|
|
|
|
* color instead of each vertex.
|
|
|
|
* @author shadekiller666
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class OBJVertexColoring1 extends Block
|
|
|
|
{
|
|
|
|
public static final OBJVertexColoring1 instance = new OBJVertexColoring1();
|
|
|
|
public static final String name = "OBJVertexColoring1";
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
private OBJVertexColoring1()
|
|
|
|
{
|
2016-05-18 12:11:56 +00:00
|
|
|
super(Material.IRON);
|
|
|
|
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
2015-07-28 21:23:34 +00:00
|
|
|
setUnlocalizedName(name);
|
2016-04-03 07:13:50 +00:00
|
|
|
setRegistryName(new ResourceLocation(MODID, name));
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isOpaqueCube(IBlockState state) { return false; }
|
2015-07-28 21:23:34 +00:00
|
|
|
|
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isFullCube(IBlockState state) { return false; }
|
2015-07-28 21:23:34 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isVisuallyOpaque() { return false; }
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
/**
|
|
|
|
* This block demonstrates how to use IProperties and IUnlistedProperties together
|
|
|
|
* in the same ExtendedBlockState. Similar to pistons, this block will face the player
|
2016-03-01 12:58:03 +00:00
|
|
|
* when placed. Unlike pistons, however; this block's model is an eyeball, because
|
2015-07-28 21:23:34 +00:00
|
|
|
* the OBJ loader can load spheres.
|
|
|
|
* @author shadekiller666
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class OBJDirectionEye extends Block
|
|
|
|
{
|
|
|
|
public static final PropertyDirection FACING = PropertyDirection.create("facing");
|
|
|
|
public static final OBJDirectionEye instance = new OBJDirectionEye();
|
|
|
|
public static final String name = "OBJDirectionEye";
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
private OBJDirectionEye()
|
|
|
|
{
|
2016-05-18 12:11:56 +00:00
|
|
|
super(Material.IRON);
|
2015-07-28 21:23:34 +00:00
|
|
|
setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
|
2016-05-18 12:11:56 +00:00
|
|
|
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
2015-07-28 21:23:34 +00:00
|
|
|
setUnlocalizedName(name);
|
2016-04-03 07:13:50 +00:00
|
|
|
setRegistryName(new ResourceLocation(MODID, name));
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
|
|
|
{
|
|
|
|
return this.getDefaultState().withProperty(FACING, getFacingFromEntity(world, pos, placer));
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta)
|
|
|
|
{
|
|
|
|
return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state)
|
|
|
|
{
|
|
|
|
return ((EnumFacing) state.getValue(FACING)).getIndex();
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public BlockStateContainer createBlockState()
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
2016-03-21 07:23:27 +00:00
|
|
|
return new ExtendedBlockState(this, new IProperty[] {FACING}, new IUnlistedProperty[] {OBJModel.OBJProperty.INSTANCE});
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isOpaqueCube(IBlockState state) { return false; }
|
2015-07-28 21:23:34 +00:00
|
|
|
|
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isFullCube(IBlockState state) { return false; }
|
2015-07-28 21:23:34 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isVisuallyOpaque() { return false; }
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
|
|
|
EnumFacing facing = (EnumFacing) state.getValue(FACING);
|
|
|
|
TRSRTransformation transform = new TRSRTransformation(facing);
|
|
|
|
OBJModel.OBJState retState = new OBJModel.OBJState(Arrays.asList(new String[]{OBJModel.Group.ALL}), true, transform);
|
2016-03-21 07:23:27 +00:00
|
|
|
return ((IExtendedBlockState) state).withProperty(OBJModel.OBJProperty.INSTANCE, retState);
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
|
|
|
|
{
|
|
|
|
if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
|
|
|
|
{
|
|
|
|
double d0 = entityIn.posY + (double)entityIn.getEyeHeight();
|
|
|
|
|
|
|
|
if (d0 - (double)clickedBlock.getY() > 2.0D)
|
|
|
|
{
|
|
|
|
return EnumFacing.DOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((double)clickedBlock.getY() - d0 > 0.0D)
|
|
|
|
{
|
|
|
|
return EnumFacing.UP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return entityIn.getHorizontalFacing();
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
/**
|
2016-03-01 12:58:03 +00:00
|
|
|
* This block uses the same model as CustomModelBlock3 does, but
|
2015-07-28 21:23:34 +00:00
|
|
|
* this class allows the player to cycle the colors of each vertex to black
|
|
|
|
* and then back to the original color when right clicking on the block.
|
|
|
|
* @author shadekiller666
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class OBJVertexColoring2 extends Block implements ITileEntityProvider
|
|
|
|
{
|
2016-03-01 12:58:03 +00:00
|
|
|
public static final OBJVertexColoring2 instance = new OBJVertexColoring2();
|
2015-07-28 21:23:34 +00:00
|
|
|
public static final String name = "OBJVertexColoring2";
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
private OBJVertexColoring2()
|
|
|
|
{
|
2016-05-18 12:11:56 +00:00
|
|
|
super(Material.IRON);
|
|
|
|
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
2015-07-28 21:23:34 +00:00
|
|
|
setUnlocalizedName(name);
|
2016-04-03 07:13:50 +00:00
|
|
|
setRegistryName(new ResourceLocation(MODID, name));
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World worldIn, int meta)
|
|
|
|
{
|
|
|
|
return new OBJVertexColoring2TileEntity();
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-05 01:43:41 +00:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
|
|
|
if (world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof OBJVertexColoring2TileEntity)
|
|
|
|
{
|
|
|
|
((OBJVertexColoring2TileEntity) world.getTileEntity(pos)).cycleColors();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2016-03-23 14:34:48 +00:00
|
|
|
@SuppressWarnings("unused")
|
2015-07-28 21:23:34 +00:00
|
|
|
public static class OBJVertexColoring2TileEntity extends TileEntity
|
|
|
|
{
|
|
|
|
private int index = 0;
|
|
|
|
private int maxIndex = 1;
|
|
|
|
private List<Vector4f> colorList = new ArrayList<Vector4f>();
|
|
|
|
private boolean hasFilledList = false;
|
|
|
|
private boolean shouldIncrement = true;
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public OBJVertexColoring2TileEntity() {}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public void cycleColors()
|
|
|
|
{
|
|
|
|
if (this.worldObj.isRemote)
|
|
|
|
{
|
|
|
|
FMLLog.info("%b", shouldIncrement);
|
2016-03-05 01:43:41 +00:00
|
|
|
/*
|
2015-07-28 21:23:34 +00:00
|
|
|
IBakedModel bakedModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelFromBlockState(this.worldObj.getBlockState(this.pos), this.worldObj, this.pos);
|
|
|
|
if (bakedModel != null && bakedModel instanceof OBJBakedModel)
|
|
|
|
{
|
|
|
|
OBJBakedModel objBaked = (OBJBakedModel) bakedModel;
|
|
|
|
ImmutableList<String> materialNames = objBaked.getModel().getMatLib().getMaterialNames();
|
|
|
|
if (!hasFilledList)
|
|
|
|
{
|
|
|
|
for (String name : materialNames)
|
|
|
|
{
|
|
|
|
if (!name.equals(OBJModel.Material.WHITE_NAME))
|
|
|
|
{
|
|
|
|
colorList.add(objBaked.getModel().getMatLib().getMaterial(name).getColor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hasFilledList = true;
|
|
|
|
}
|
|
|
|
maxIndex = materialNames.size();
|
|
|
|
if (this.shouldIncrement && index + 1 < maxIndex)
|
|
|
|
{
|
|
|
|
FMLLog.info("incrementing");
|
|
|
|
String name = materialNames.get(index);
|
2016-03-05 01:43:41 +00:00
|
|
|
// no
|
2015-07-28 21:23:34 +00:00
|
|
|
objBaked.getModel().getMatLib().changeMaterialColor(name, 0xFF000000);
|
|
|
|
objBaked.scheduleRebake();
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
else if (index - 1 >= 0)
|
|
|
|
{
|
|
|
|
index--;
|
|
|
|
this.shouldIncrement = index == 0;
|
|
|
|
int color = 0;
|
|
|
|
color |= (int) (colorList.get(index).getW() * 255) << 24;
|
|
|
|
color |= (int) (colorList.get(index).getX() * 255) << 16;
|
|
|
|
color |= (int) (colorList.get(index).getY() * 255) << 8;
|
|
|
|
color |= (int) (colorList.get(index).getZ() * 255);
|
|
|
|
String name = materialNames.get(index);
|
|
|
|
if (!name.equals(OBJModel.Material.WHITE_NAME))
|
|
|
|
{
|
2016-03-05 01:43:41 +00:00
|
|
|
// FIXME
|
2015-07-28 21:23:34 +00:00
|
|
|
objBaked.getModel().getMatLib().changeMaterialColor(name, color);
|
|
|
|
objBaked.scheduleRebake();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos);
|
2016-03-05 01:43:41 +00:00
|
|
|
}*/
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
/**
|
|
|
|
* This block is a debug block that faces the player when placed, like a piston.
|
|
|
|
* @author shadekiller666
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class OBJDirectionBlock extends Block
|
|
|
|
{
|
|
|
|
public static final PropertyDirection FACING = PropertyDirection.create("facing");
|
|
|
|
public static final OBJDirectionBlock instance = new OBJDirectionBlock();
|
|
|
|
public static final String name = "OBJDirectionBlock";
|
2016-03-21 07:23:27 +00:00
|
|
|
public ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[]{FACING}, new IUnlistedProperty[]{OBJModel.OBJProperty.INSTANCE});
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
private OBJDirectionBlock()
|
|
|
|
{
|
2016-05-18 12:11:56 +00:00
|
|
|
super(Material.IRON);
|
2015-07-28 21:23:34 +00:00
|
|
|
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
|
2016-05-18 12:11:56 +00:00
|
|
|
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
2015-07-28 21:23:34 +00:00
|
|
|
setUnlocalizedName(MODID + ":" + name);
|
2016-04-03 07:13:50 +00:00
|
|
|
setRegistryName(new ResourceLocation(MODID, name));
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isOpaqueCube(IBlockState state) { return false; }
|
2015-07-28 21:23:34 +00:00
|
|
|
|
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isFullCube(IBlockState state) { return false; }
|
2015-07-28 21:23:34 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isVisuallyOpaque() { return false; }
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
|
|
|
{
|
|
|
|
return this.getDefaultState().withProperty(FACING, getFacingFromEntity(world, pos, placer));
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta)
|
|
|
|
{
|
|
|
|
return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state)
|
|
|
|
{
|
|
|
|
return ((EnumFacing) state.getValue(FACING)).getIndex();
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
|
|
|
//Only return an IExtendedBlockState from this method and createState(), otherwise block placement will break!
|
|
|
|
EnumFacing facing = (EnumFacing) state.getValue(FACING);
|
|
|
|
TRSRTransformation transform = new TRSRTransformation(facing);
|
|
|
|
OBJModel.OBJState newState = new OBJModel.OBJState(Lists.newArrayList(OBJModel.Group.ALL), true, transform);
|
2016-03-21 07:23:27 +00:00
|
|
|
return ((IExtendedBlockState) state).withProperty(OBJModel.OBJProperty.INSTANCE, newState);
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public BlockStateContainer createBlockState()
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
2016-03-21 07:23:27 +00:00
|
|
|
return new ExtendedBlockState(this, new IProperty[]{FACING}, new IUnlistedProperty[]{OBJModel.OBJProperty.INSTANCE});
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
|
|
|
|
{
|
|
|
|
if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
|
|
|
|
{
|
|
|
|
double d0 = entityIn.posY + (double)entityIn.getEyeHeight();
|
|
|
|
|
|
|
|
if (d0 - (double)clickedBlock.getY() > 2.0D)
|
|
|
|
{
|
|
|
|
return EnumFacing.UP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((double)clickedBlock.getY() - d0 > 0.0D)
|
|
|
|
{
|
|
|
|
return EnumFacing.DOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return entityIn.getHorizontalFacing().getOpposite();
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
/**
|
|
|
|
* This block is a testing block that will be used to test the use
|
|
|
|
* of "custom" data defined in a forge blockstate json. WIP, ignore for now.
|
|
|
|
* @author shadekiller666
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class OBJCustomDataBlock extends Block
|
|
|
|
{
|
|
|
|
public static final PropertyBool NORTH = PropertyBool.create("north");
|
|
|
|
public static final PropertyBool SOUTH = PropertyBool.create("south");
|
|
|
|
public static final PropertyBool WEST = PropertyBool.create("west");
|
|
|
|
public static final PropertyBool EAST = PropertyBool.create("east");
|
|
|
|
public static final OBJCustomDataBlock instance = new OBJCustomDataBlock();
|
|
|
|
public static final String name = "OBJCustomDataBlock";
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
private OBJCustomDataBlock()
|
|
|
|
{
|
2016-05-18 12:11:56 +00:00
|
|
|
super(Material.IRON);
|
2015-07-28 21:23:34 +00:00
|
|
|
this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, false).withProperty(SOUTH, false).withProperty(WEST, false).withProperty(EAST, false));
|
2016-05-18 12:11:56 +00:00
|
|
|
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
2015-07-28 21:23:34 +00:00
|
|
|
setUnlocalizedName(MODID + ":" + name);
|
2016-04-03 07:13:50 +00:00
|
|
|
setRegistryName(new ResourceLocation(MODID, name));
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isOpaqueCube(IBlockState state)
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isFullCube(IBlockState state)
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public boolean canConnectTo(IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
|
|
|
Block block = world.getBlockState(pos).getBlock();
|
|
|
|
return block instanceof OBJCustomDataBlock;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
|
|
|
return state.withProperty(NORTH, this.canConnectTo(world, pos.north())).withProperty(SOUTH, this.canConnectTo(world, pos.south())).withProperty(WEST, this.canConnectTo(world, pos.west())).withProperty(EAST, this.canConnectTo(world, pos.east()));
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public BlockStateContainer createBlockState()
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
2016-03-01 12:58:03 +00:00
|
|
|
return new BlockStateContainer(this, new IProperty[]{NORTH, SOUTH, WEST, EAST});
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
/**
|
|
|
|
* This block uses the same model as CustomModelBlock4, but instead of facing the
|
|
|
|
* player when placed, this one ALWAYS faces the player. I know, creepy right?
|
|
|
|
* @author shadekiller666
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class OBJDynamicEye extends Block implements ITileEntityProvider
|
|
|
|
{
|
|
|
|
public static final OBJDynamicEye instance = new OBJDynamicEye();
|
|
|
|
public static final String name = "OBJDynamicEye";
|
2016-03-21 07:23:27 +00:00
|
|
|
public ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] {OBJModel.OBJProperty.INSTANCE});
|
2015-07-28 21:23:34 +00:00
|
|
|
private OBJDynamicEye()
|
|
|
|
{
|
2016-05-18 12:11:56 +00:00
|
|
|
super(Material.IRON);
|
|
|
|
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
2015-07-28 21:23:34 +00:00
|
|
|
setUnlocalizedName(MODID + ":" + name);
|
2016-04-03 07:13:50 +00:00
|
|
|
setRegistryName(new ResourceLocation(MODID, name));
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World worldIn, int meta)
|
|
|
|
{
|
|
|
|
return new OBJDynamicEyeTileEntity();
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isOpaqueCube(IBlockState state)
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public boolean isFullCube(IBlockState state)
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public boolean hasTileEntity(IBlockState state)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
|
|
|
if (world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof OBJDynamicEyeTileEntity)
|
|
|
|
{
|
|
|
|
OBJDynamicEyeTileEntity te = (OBJDynamicEyeTileEntity) world.getTileEntity(pos);
|
|
|
|
if (te.state != null)
|
|
|
|
{
|
2016-03-21 07:23:27 +00:00
|
|
|
return ((IExtendedBlockState) this.state.getBaseState()).withProperty(OBJModel.OBJProperty.INSTANCE, te.state);
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
2016-03-01 12:58:03 +00:00
|
|
|
public BlockStateContainer createBlockState()
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
2016-03-21 07:23:27 +00:00
|
|
|
return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] {OBJModel.OBJProperty.INSTANCE});
|
2015-07-28 21:23:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-11-09 21:03:39 +00:00
|
|
|
public static class OBJDynamicEyeTileEntity extends TileEntity implements ITickable
|
2015-07-28 21:23:34 +00:00
|
|
|
{
|
|
|
|
public OBJModel.OBJState state;
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
public OBJDynamicEyeTileEntity()
|
|
|
|
{
|
|
|
|
this.state = new OBJModel.OBJState(Lists.newArrayList(OBJModel.Group.ALL), true);
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
2015-07-28 21:23:34 +00:00
|
|
|
@Override
|
|
|
|
public void update()
|
|
|
|
{
|
|
|
|
if (this.worldObj.isRemote)
|
|
|
|
{
|
|
|
|
Vector3d teLoc = new Vector3d(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
|
|
|
|
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
|
|
|
Vector3d playerLoc = new Vector3d();
|
|
|
|
playerLoc.setX(player.posX);
|
2015-11-09 21:03:39 +00:00
|
|
|
playerLoc.setY(player.posY + player.getEyeHeight());
|
2015-07-28 21:23:34 +00:00
|
|
|
playerLoc.setZ(player.posZ);
|
|
|
|
Vector3d lookVec = new Vector3d(playerLoc.getX() - teLoc.getX(), playerLoc.getY() - teLoc.getY(), playerLoc.getZ() - teLoc.getZ());
|
|
|
|
double angleYaw = Math.atan2(lookVec.getZ(), lookVec.getX()) - Math.PI/2d;
|
|
|
|
double anglePitch = Math.atan2(lookVec.getY(), Math.sqrt(lookVec.getX() * lookVec.getX() + lookVec.getZ() * lookVec.getZ()));
|
|
|
|
AxisAngle4d yaw = new AxisAngle4d(0, 1, 0, -angleYaw);
|
|
|
|
AxisAngle4d pitch = new AxisAngle4d(1, 0, 0, -anglePitch);
|
|
|
|
Quat4f rot = new Quat4f(0, 0, 0, 1);
|
|
|
|
Quat4f yawQuat = new Quat4f();
|
|
|
|
Quat4f pitchQuat = new Quat4f();
|
|
|
|
yawQuat.set(yaw);
|
|
|
|
rot.mul(yawQuat);
|
|
|
|
pitchQuat.set(pitch);
|
|
|
|
rot.mul(pitchQuat);
|
|
|
|
Matrix4f matrix = new Matrix4f();
|
|
|
|
matrix.setIdentity();
|
|
|
|
matrix.setRotation(rot);
|
|
|
|
TRSRTransformation transform = new TRSRTransformation(matrix);
|
|
|
|
transform = TRSRTransformation.blockCenterToCorner(transform);
|
|
|
|
this.state = new OBJModel.OBJState(Lists.newArrayList(OBJModel.Group.ALL), true, transform);
|
|
|
|
this.worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-28 04:10:54 +00:00
|
|
|
}
|