Created
June 25, 2015 20:10
-
-
Save StillManic/1bc82a480ea80e4938c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Mod(modid = ModelLoaderRegistryDebug.MODID, version = ModelLoaderRegistryDebug.VERSION) | |
public class ModelLoaderRegistryDebug | |
{ | |
public static final String MODID = "ForgeDebugModelLoaderRegistry"; | |
public static final String VERSION = "1.0"; | |
@EventHandler | |
public void preInit(FMLPreInitializationEvent event) | |
{ | |
GameRegistry.registerBlock(CustomModelBlock.instance, CustomModelBlock.name); | |
GameRegistry.registerBlock(CustomModelBlock2.instance, CustomModelBlock2.name); | |
GameRegistry.registerBlock(CustomModelBlock3.instance, CustomModelBlock3.name); | |
GameRegistry.registerBlock(CustomModelBlock4.instance, CustomModelBlock4.name); | |
GameRegistry.registerTileEntity(CustomTileEntity2.class, CustomModelBlock2.name); | |
if (event.getSide() == Side.CLIENT) | |
clientPreInit(); | |
} | |
private void clientPreInit() | |
{ | |
B3DLoader.instance.addDomain(MODID.toLowerCase()); | |
Item item = Item.getItemFromBlock(CustomModelBlock.instance); | |
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + CustomModelBlock.name, "inventory")); | |
OBJLoader.instance.addDomain(MODID.toLowerCase()); | |
Item item2 = Item.getItemFromBlock(CustomModelBlock2.instance); | |
ModelLoader.setCustomModelResourceLocation(item2, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + CustomModelBlock2.name, "inventory")); | |
Item item3 = Item.getItemFromBlock(CustomModelBlock3.instance); | |
ModelLoader.setCustomModelResourceLocation(item3, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + CustomModelBlock3.name, "inventory")); | |
Item item4 = Item.getItemFromBlock(CustomModelBlock4.instance); | |
ModelLoader.setCustomModelResourceLocation(item4, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + CustomModelBlock4.name, "inventory")); | |
} | |
public static class CustomModelBlock extends Block | |
{ | |
public static final CustomModelBlock instance = new CustomModelBlock(); | |
public static final String name = "CustomModelBlock"; | |
private int counter = 1; | |
private ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{ B3DLoader.B3DFrameProperty.instance }); | |
private CustomModelBlock() | |
{ | |
super(Material.iron); | |
setCreativeTab(CreativeTabs.tabBlock); | |
setUnlocalizedName(MODID + ":" + name); | |
} | |
@Override | |
public boolean isOpaqueCube() { return false; } | |
@Override | |
public boolean isFullCube() { return false; } | |
@Override | |
public boolean isVisuallyOpaque() { return false; } | |
@Override | |
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) | |
{ | |
B3DLoader.B3DState newState = new B3DLoader.B3DState(null, counter); | |
return ((IExtendedBlockState)this.state.getBaseState()).withProperty(B3DLoader.B3DFrameProperty.instance, newState); | |
} | |
@Override | |
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) | |
{ | |
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; | |
} | |
} | |
public static class CustomModelBlock2 extends Block implements ITileEntityProvider | |
{ | |
public static final CustomModelBlock2 instance = new CustomModelBlock2(); | |
public static final String name = "CustomModelBlock2"; | |
private ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{OBJModel.OBJModelProperty.instance}); | |
private CustomModelBlock2() | |
{ | |
super(Material.iron); | |
setCreativeTab(CreativeTabs.tabBlock); | |
setUnlocalizedName(MODID + ":" + name); | |
} | |
@Override | |
public TileEntity createNewTileEntity(World worldIn, int meta) | |
{ | |
return new CustomTileEntity2(); | |
} | |
@Override | |
public boolean isOpaqueCube() { return false; } | |
@Override | |
public boolean isFullCube() { return false; } | |
@Override | |
public boolean isVisuallyOpaque() { return false; } | |
@Override | |
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) | |
{ | |
try | |
{ | |
CustomTileEntity2 tileEntity = (CustomTileEntity2) world.getTileEntity(pos); | |
IModel model = ModelLoaderRegistry.getModel(new ResourceLocation(MODID.toLowerCase(), "block/tesseract.obj")); | |
ChatComponentText text = new ChatComponentText(""); | |
if (tileEntity != null) text = new ChatComponentText("" + tileEntity.getCounter()); | |
else text = new ChatComponentText("tile entity null"); | |
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(text); | |
List<String> elements = new ArrayList<String>(); | |
elements.addAll(((OBJModel) model).getMatLib().getElements().keySet()); | |
List<String> visible = new ArrayList<String>(); | |
if (tileEntity != null) | |
{ | |
for (int i = tileEntity.getCounter(); i >= 0; i--) | |
{ | |
visible.add(elements.get(i)); | |
} | |
} | |
OBJModel.OBJState retState = ((OBJModel) model).new OBJState(visible, (OBJModel) model); | |
return ((IExtendedBlockState) this.state.getBaseState()).withProperty(OBJModel.OBJModelProperty.instance, retState); | |
} | |
catch (IOException e) | |
{ | |
return state; | |
} | |
} | |
@Override | |
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) | |
{ | |
if (world.getTileEntity(pos) == null) world.setTileEntity(pos, new CustomTileEntity2()); | |
IModel model = ModelLoaderRegistry.getMissingModel(); | |
CustomTileEntity2 tileEntity = (CustomTileEntity2) world.getTileEntity(pos); | |
try | |
{ | |
model = ModelLoaderRegistry.getModel(new ResourceLocation(MODID.toLowerCase() + ":" + "block/tesseract.obj")); | |
} | |
catch (IOException e) | |
{ | |
model = ModelLoaderRegistry.getMissingModel(); | |
} | |
if (player.isSneaking()) | |
{ | |
tileEntity.decrement(); | |
} | |
else | |
{ | |
if (model != ModelLoaderRegistry.getMissingModel()) | |
{ | |
tileEntity.setMax(((OBJModel) model).getMatLib().getElements().keySet().size() - 1); | |
tileEntity.increment(); | |
} | |
} | |
world.markBlockRangeForRenderUpdate(pos, pos); | |
return false; | |
} | |
@Override | |
public boolean hasTileEntity(IBlockState state) | |
{ | |
return true; | |
} | |
} | |
public static class CustomTileEntity2 extends TileEntity | |
{ | |
private int counter = 0; | |
private int max = 1; | |
public CustomTileEntity2() {} | |
public int getCounter() | |
{ | |
return this.counter; | |
} | |
public int getMax() | |
{ | |
return this.max; | |
} | |
public void increment() | |
{ | |
if (this.counter == max) this.counter = -1; | |
this.counter++; | |
} | |
public void decrement() | |
{ | |
if (this.counter == 0) this.counter = max + 1; | |
this.counter--; | |
} | |
public void reset() | |
{ | |
this.counter = 0; | |
this.max = 1; | |
} | |
public void setMax(int max) | |
{ | |
this.max = max; | |
} | |
public void setToMax() | |
{ | |
this.counter = this.max; | |
} | |
} | |
public static class CustomModelBlock3 extends Block | |
{ | |
public static final CustomModelBlock3 instance = new CustomModelBlock3(); | |
public static final String name = "CustomModelBlock3"; | |
private CustomModelBlock3() | |
{ | |
super(Material.iron); | |
setCreativeTab(CreativeTabs.tabBlock); | |
setUnlocalizedName(name); | |
} | |
@Override | |
public boolean isOpaqueCube() { return false; } | |
@Override | |
public boolean isFullCube() { return false; } | |
@Override | |
public boolean isVisuallyOpaque() { return false; } | |
} | |
public static class CustomModelBlock4 extends Block | |
{ | |
public static final CustomModelBlock4 instance = new CustomModelBlock4(); | |
public static final String name = "CustomModelBlock4"; | |
// public static final PropertyDirection FACING = PropertyDirection.create("facing"); | |
// private ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[] {FACING}, new IUnlistedProperty[0]); | |
private CustomModelBlock4() | |
{ | |
super(Material.iron); | |
setCreativeTab(CreativeTabs.tabBlock); | |
setUnlocalizedName(name); | |
// this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); | |
} | |
@Override | |
public boolean isOpaqueCube() { return false; } | |
@Override | |
public boolean isFullCube() { return false; } | |
@Override | |
public boolean isVisuallyOpaque() { return false; } | |
// @Override | |
// protected BlockState createBlockState() | |
// { | |
// return new BlockState(this, new IProperty[] {FACING}); | |
// } | |
// @Override | |
// public int getMetaFromState(IBlockState state) | |
// { | |
// EnumFacing facing = (EnumFacing) state.getValue(FACING); | |
// return facing.ordinal(); | |
// } | |
// | |
// @Override | |
// public IBlockState getStateFromMeta(int meta) | |
// { | |
// return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta)); | |
// } | |
// @Override | |
// public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) | |
// { | |
// return this.state.getBaseState().withProperty(FACING, state.getValue(FACING)); | |
// } | |
// | |
// @Override | |
// public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) | |
// { | |
// world.setBlockState(pos, this.state.getBaseState().withProperty(FACING, this.getFacingFromEntity(world, pos, placer))); | |
// } | |
// | |
// 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(); | |
// } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment