Posted May 17, 201510 yr Hello all, I am having trouble rendering my custom modeled block - I wanted my block's model to face different directions depending on which way the player is facing, which works. The problem arises when I try and make and render my block as an item as well. Whenever I enter the game and the item is visible, the game crashes immediately. I believe I am doing it right, because when I remove the directional code, it renders fine with no crashes. How would I make these two functions work together? My code is as follows: Block Class public class PottedPlantProp extends BlockContainer { public PottedPlantProp(Material material) { super(material); this.setCreativeTab(DesconCreativeTabs.tabExterior); this.setHarvestLevel("", 1); this.setHardness(1F); this.setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.750F, 0.9375F); this.setBlockTextureName(Main.modID + ":" + "textures/blocks/pottedplant.png"); } public int getRenderType() { return -1; } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } @Override public TileEntity createNewTileEntity(World var1, int var2) { return new TileEntityPottedPlant(); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5)); } //Directional Code /*public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack) { int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, l, 3); }*/ } ClientProxy //Potted Plant TileEntitySpecialRenderer renderPottedPlant = new RenderPottedPlant(); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPottedPlant.class, renderPottedPlant); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(PropsGeneral.pottedplant), new ItemRenderPottedPlant(renderPottedPlant, new TileEntityPottedPlant())); ItemRenderer public class ItemRenderPottedPlant implements IItemRenderer { TileEntitySpecialRenderer render; private TileEntity entity; public ItemRenderPottedPlant(TileEntitySpecialRenderer render, TileEntity entity) { this.entity = entity; this.render = render; } @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { return true; } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return true; } @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { if(type == IItemRenderer.ItemRenderType.ENTITY) GL11.glTranslatef(-0.5F, 0.0F, -0.5F); this.render.renderTileEntityAt(this.entity, 0.0D, 0.0D, 0.0D, 0.0F); } } Block Renderer public class RenderPottedPlant extends TileEntitySpecialRenderer { private static final ResourceLocation texture = new ResourceLocation(Main.modID + ":" + "textures/props/PottedPlantTexture.png"); private ModelPottedPlant model; public RenderPottedPlant() { this.model = new ModelPottedPlant(); } @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { /*World world = tileEntity.getWorldObj(); int dir = world.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); */ GL11.glPushMatrix(); GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F); GL11.glRotatef(180, 0F, 0F, 1F); //GL11.glRotatef(dir * (90F), 0F, 1F, 0F); this.bindTexture(texture); GL11.glPushMatrix(); this.model.renderModel(0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); } } P.S. In the state the code is in above, the directional code has been commented out, so that the rendering works
May 17, 201510 yr I think(dont know for sure) that its crashing because an Item is not a real tileEntity. This means the game can't calculate the rotation which will cause eventually. So I would recommend trying to make an separate render code, where you don't set(dynamicly) any rotation, and use that for you Item rendering. or use an icon instead of the model for itemEntity, since the game will slowly rotate the model, which in your case will cause a conflict. Projects: Discontinued: - N2ConfigAPI - Meachanical Crafting Table Latest: - CollectionUtils Coöperations: - InGameConfigManager
May 18, 201510 yr Author The crash report is as follows: [17:31:43] [Client thread/FATAL]: Reported exception thrown! net.minecraft.util.ReportedException: Rendering item at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:624) ~[RenderItem.class:?] at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973) ~[GuiIngame.class:?] at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209) ~[GuiIngameForge.class:?] at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144) ~[GuiIngameForge.class:?] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1114) ~[EntityRenderer.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1056) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?] at GradleStart.main(GradleStart.java:45) [start/:?] Caused by: java.lang.NullPointerException at com.descon.renderer.RenderPottedPlant.renderTileEntityAt(RenderPottedPlant.java:27) ~[RenderPottedPlant.class:?] //int dir = world.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); at com.descon.itemrenderer.ItemRenderPottedPlant.renderItem(ItemRenderPottedPlant.java:35) ~[itemRenderPottedPlant.class:?] //this.render.renderTileEntityAt(this.entity, 0.0D, 0.0D, 0.0D, 0.0F); at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:183) ~[ForgeHooksClient.class:?] at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:583) ~[RenderItem.class:?] ... 15 more [17:31:43] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ---- Time: 18/05/15 5:31 PM Description: Rendering item java.lang.NullPointerException: Rendering item at com.descon.renderer.RenderPottedPlant.renderTileEntityAt(RenderPottedPlant.java:27) at com.descon.itemrenderer.ItemRenderPottedPlant.renderItem(ItemRenderPottedPlant.java:35) at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:183) at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:583) at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973) at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209) at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1114) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1056) at net.minecraft.client.Minecraft.run(Minecraft.java:951) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) at GradleStart.main(GradleStart.java:45) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at com.descon.renderer.RenderPottedPlant.renderTileEntityAt(RenderPottedPlant.java:27) at com.descon.itemrenderer.ItemRenderPottedPlant.renderItem(ItemRenderPottedPlant.java:35) at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:183) -- Item being rendered -- Details: Item Type: net.minecraft.item.ItemBlock@34d644b5 Item Aux: 0 Item NBT: null Item Foil: false Stacktrace: at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:583) at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973) at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209) at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['Player37'/264, l='MpServer', x=59.02, y=70.62, z=232.56]] Chunk stats: MultiplayerChunkCache: 10, 10 Level seed: 0 Level generator: ID 00 - default, ver 1. Features enabled: false Level generator options: Level spawn location: World: (56,64,248), Chunk: (at 8,4,8 in 3,15; contains blocks 48,0,240 to 63,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 1321 game time, 1321 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 6 total; [EntityItem['item.item.seeds'/114, l='MpServer', x=32.81, y=63.13, z=212.25], EntitySquid['Squid'/115, l='MpServer', x=41.59, y=59.28, z=217.16], EntitySquid['Squid'/116, l='MpServer', x=47.94, y=55.34, z=209.31], EntityClientPlayerMP['Player37'/264, l='MpServer', x=59.02, y=70.62, z=232.56], EntitySquid['Squid'/125, l='MpServer', x=51.97, y=55.00, z=212.94], EntitySquid['Squid'/126, l='MpServer', x=52.84, y=54.00, z=209.50]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2555) at net.minecraft.client.Minecraft.run(Minecraft.java:973) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) at GradleStart.main(GradleStart.java:45) This... Caused by: java.lang.NullPointerException at com.descon.renderer.RenderPottedPlant.renderTileEntityAt(RenderPottedPlant.java:27) ~[RenderPottedPlant.class:?] ...is where my code is first referenced in the crash log I believe Thanks, -Whyneb360 P.S. In the above crash report, I annotated which line of code related to the reference.
May 18, 201510 yr Hi so... either tileEntity is null or tileEntity.world is null. Set a breakpoint or System.out.println there, to find out which one... In this case tileEntity.world is null. You are trying to pull information about a block from a TileEntity which you created from nothing new ItemRenderPottedPlant(renderPottedPlant, new TileEntityPottedPlant())) Your renderer needs to check for that, and use a default value if it's an item not a block. eg if (tileEntity.hasWorldObj()) { get value from world block } else { use default value } -TGG
May 19, 201510 yr Author Thank you for your response, however I'm not sure where to put the the if statement you mentioned, or what the default value would be. Sorry if this seems like an obvious question
May 19, 201510 yr Hi Check out TileEntityChestRenderer, it has a similar example. The key problem is - your TileEntityRenderer is trying to use the TileEntity's direction to figure out which direction to render. That only makes sense if your TileEntity is associated with a block that you've placed in the world. The if statement goes in your renderer before you try to use the world object to retrieve the direction. -TGG
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.