From b175d265b9643faf3408754f6923a8f55f6ee5d3 Mon Sep 17 00:00:00 2001 From: RainWarrior Date: Wed, 2 Sep 2015 07:26:42 +0300 Subject: [PATCH] Much requested temporary hack for items and TESRs. Context: #1582, #1597, #1713, #2058 and others. --- .../TileEntityItemStackRenderer.java.patch | 10 ++ .../client/ForgeHooksClient.java | 33 +++++ .../minecraftforge/debug/ItemTileDebug.java | 137 ++++++++++++++++++ .../models/item/custom_model_block.json | 3 + 4 files changed, 183 insertions(+) create mode 100644 patches/minecraft/net/minecraft/client/renderer/tileentity/TileEntityItemStackRenderer.java.patch create mode 100644 src/test/java/net/minecraftforge/debug/ItemTileDebug.java create mode 100644 src/test/resources/assets/forgedebugitemtile/models/item/custom_model_block.json diff --git a/patches/minecraft/net/minecraft/client/renderer/tileentity/TileEntityItemStackRenderer.java.patch b/patches/minecraft/net/minecraft/client/renderer/tileentity/TileEntityItemStackRenderer.java.patch new file mode 100644 index 000000000..3b547aafd --- /dev/null +++ b/patches/minecraft/net/minecraft/client/renderer/tileentity/TileEntityItemStackRenderer.java.patch @@ -0,0 +1,10 @@ +--- ../src-base/minecraft/net/minecraft/client/renderer/tileentity/TileEntityItemStackRenderer.java ++++ ../src-work/minecraft/net/minecraft/client/renderer/tileentity/TileEntityItemStackRenderer.java +@@ -79,6 +79,7 @@ + { + TileEntityRendererDispatcher.field_147556_a.func_147549_a(this.field_147718_c, 0.0D, 0.0D, 0.0D, 0.0F); + } ++ else if (block != Blocks.field_150486_ae) net.minecraftforge.client.ForgeHooksClient.renderTileItem(p_179022_1_.func_77973_b(), p_179022_1_.func_77960_j()); + else + { + TileEntityRendererDispatcher.field_147556_a.func_147549_a(this.field_147717_b, 0.0D, 0.0D, 0.0D, 0.0F); diff --git a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java index bd24a5fe3..90369a120 100644 --- a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java +++ b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java @@ -7,6 +7,7 @@ import static org.lwjgl.opengl.GL20.*; import java.nio.ByteBuffer; import java.nio.FloatBuffer; +import java.util.Map; import javax.vecmath.Matrix4f; import javax.vecmath.Vector3d; @@ -33,6 +34,8 @@ import net.minecraft.client.renderer.block.model.ItemTransformVec3f; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.vertex.VertexFormatElement; import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage; import net.minecraft.client.resources.I18n; @@ -44,7 +47,9 @@ import net.minecraft.client.settings.GameSettings; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumWorldBlockLayer; @@ -79,6 +84,8 @@ import org.lwjgl.opengl.GL11; //import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*; //import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*; +import com.google.common.collect.Maps; + public class ForgeHooksClient { //private static final ResourceLocation ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); @@ -678,4 +685,30 @@ public class ForgeHooksClient renderer.putColorRGBA(renderer.getColorIndex(i + 1), ncr, ncg, ncb, nca); } } + + private static Map, Class> tileItemMap = Maps.newHashMap(); + + public static void renderTileItem(Item item, int metadata) + { + Class tileClass = tileItemMap.get(Pair.of(item, + metadata)); + if (tileClass != null) + { + TileEntitySpecialRenderer r = TileEntityRendererDispatcher.instance + .getSpecialRendererByClass(tileClass); + if (r != null) + { + r.renderTileEntityAt(null, 0, 0, 0, 0, -1); + } + } + } + + /** + * @deprecated Will be removed as soon as possible, hopefully 1.9. + */ + @Deprecated + public static void registerTESRItemStack(Item item, int metadata, Class TileClass) + { + tileItemMap.put(Pair.of(item, metadata), TileClass); + } } diff --git a/src/test/java/net/minecraftforge/debug/ItemTileDebug.java b/src/test/java/net/minecraftforge/debug/ItemTileDebug.java new file mode 100644 index 000000000..7c2668c65 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/ItemTileDebug.java @@ -0,0 +1,137 @@ +package net.minecraftforge.debug; + +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.debug.ModelBakeEventDebug.BakeEventHandler; +import net.minecraftforge.debug.ModelBakeEventDebug.ClientProxy; +import net.minecraftforge.debug.ModelBakeEventDebug.CustomModel; +import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; +import static org.lwjgl.opengl.GL11.*; + +@Mod(modid = ItemTileDebug.MODID) +public class ItemTileDebug +{ + public static final String MODID = "ForgeDebugItemTile"; + + private static String blockName = MODID.toLowerCase() + ":" + TestBlock.name; + + @SidedProxy(serverSide = "net.minecraftforge.debug.ItemTileDebug$CommonProxy", clientSide = "net.minecraftforge.debug.ItemTileDebug$ClientProxy") + public static CommonProxy proxy; + + @EventHandler + public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); } + + public static class CommonProxy + { + public void preInit(FMLPreInitializationEvent event) + { + GameRegistry.registerBlock(TestBlock.instance, TestBlock.name); + GameRegistry.registerTileEntity(CustomTileEntity.class, MODID.toLowerCase() + ":custom_tile_entity"); + } + } + + public static class ClientProxy extends CommonProxy + { + private static ModelResourceLocation itemLocation = new ModelResourceLocation(blockName, "inventory"); + + @Override + public void preInit(FMLPreInitializationEvent event) + { + super.preInit(event); + ClientRegistry.bindTileEntitySpecialRenderer(CustomTileEntity.class, TestTESR.instance); + Item item = Item.getItemFromBlock(TestBlock.instance); + ForgeHooksClient.registerTESRItemStack(item, 0, CustomTileEntity.class); + ModelLoader.setCustomModelResourceLocation(item, 0, itemLocation); + MinecraftForge.EVENT_BUS.register(BakeEventHandler.instance); + } + } + + public static class BakeEventHandler + { + public static final BakeEventHandler instance = new BakeEventHandler(); + + private BakeEventHandler() {}; + + @SubscribeEvent + public void onModelBakeEvent(ModelBakeEvent event) + { + event.modelManager.getBlockModelShapes().registerBuiltInBlocks(TestBlock.instance); + } + } + + public static class TestTESR extends TileEntitySpecialRenderer + { + private static final TestTESR instance = new TestTESR(); + + private TestTESR() {} + + @Override + public void renderTileEntityAt(TileEntity p_180535_1_, double x, double y, double z, float p_180535_8_, int p_180535_9_) + { + glPushMatrix(); + glTranslated(x, y, z); + GlStateManager.disableTexture2D(); + GlStateManager.disableLighting(); + glColor4f(.2f, 1, .1f, 1); + glBegin(GL_QUADS); + glVertex3f(0, .5f, 0); + glVertex3f(0, .5f, 1); + glVertex3f(1, .5f, 1); + glVertex3f(1, .5f, 0); + glEnd(); + glPopMatrix(); + GlStateManager.enableTexture2D(); + GlStateManager.enableLighting(); + } + } + + public static class TestBlock extends BlockContainer + { + public static final TestBlock instance = new TestBlock(); + public static final String name = "custom_model_block"; + + private TestBlock() + { + 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 TileEntity createNewTileEntity(World world, int meta) + { + return new CustomTileEntity(); + } + } + + public static class CustomTileEntity extends TileEntity {} +} diff --git a/src/test/resources/assets/forgedebugitemtile/models/item/custom_model_block.json b/src/test/resources/assets/forgedebugitemtile/models/item/custom_model_block.json new file mode 100644 index 000000000..43a272a60 --- /dev/null +++ b/src/test/resources/assets/forgedebugitemtile/models/item/custom_model_block.json @@ -0,0 +1,3 @@ +{ + "parent": "builtin/entity" +}