Jump to content

Recommended Posts

Posted

i am trying to render a item that is in the inventory of the block on a tileentity/block but when i add the item in the slot it crashes

 

 

ublic class TileentityPedistalRenderer extends TileEntitySpecialRenderer {

        //The model of your block
        private final PedistalModel model;
        
        public TileentityPedistalRenderer() {
                this.model = new PedistalModel();
                customRenderItem = new RenderItem()
    	        {
    	            @Override
    	            public boolean shouldBob()
    	            {
    	                return false;
    	            }
    	        };
        
               
        }
        	private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
        		  int meta = world.getBlockMetadata(x, y, z);
                  GL11.glRotatef(meta * (90), 0.0F, 1.0F, 0.0F);
        	}
        	
        
        	private final RenderItem customRenderItem;
		private Entity entItem;
        
        
        @Override
        public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
        	 GL11.glPushMatrix();
             GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
                ResourceLocation texture = new ResourceLocation("baublelicious:textures/models/TileentityPedistal.png");
                FMLClientHandler.instance().getClient().renderEngine.bindTexture(texture);                  
                GL11.glPushMatrix();
                GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
                GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
                adjustRotatePivotViaMeta(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
                this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
                GL11.glPopMatrix();
                GL11.glPopMatrix();
                
                GL11.glPushMatrix();
                TileentityPedistalEntity tileAltar = (TileentityPedistalEntity) te;
                if (tileAltar.getStackInSlot(0) != null)
                {
                    float scaleFactor = getGhostItemScaleFactor(tileAltar.getStackInSlot(0));
                    EntityItem ghostEntityItem = new EntityItem(tileAltar.getWorldObj());
                    ghostEntityItem.hoverStart = 0.0F;
                    ghostEntityItem.setEntityItemStack(tileAltar.getStackInSlot(0));
                    float displacement = 0.2F;

                    if (ghostEntityItem.getEntityItem().getItem() instanceof ItemBlock)
                    {
                        GL11.glTranslatef((float) x + 0.5F, (float) y + displacement + 0.7F, (float) z + 0.5F);
                    } else
                    {
                        GL11.glTranslatef((float) x + 0.5F, (float) y + displacement + 10.4f / 16.0f, (float) z + 0.5F - 0.0625f * 2f);
                    }
                    GL11.glScalef(scaleFactor, scaleFactor, scaleFactor);

                    if (!(ghostEntityItem.getEntityItem().getItem() instanceof ItemBlock))
                    {
                        GL11.glRotatef(90f, 1.0f, 0.0f, 0.0F);
                    }

                    customRenderItem.doRender(ghostEntityItem, 0, 0, 0, 0, 0);
                }
                GL11.glPopMatrix();
        }
              
                private float getGhostItemScaleFactor(ItemStack itemStack)
                {
                    float scaleFactor = 1.5F;

                    if (itemStack != null)
                    {
                        if (itemStack.getItem() instanceof ItemBlock)
                        {
                            switch (customRenderItem.getMiniBlockCount(itemStack, (byte) 1))
                            {
                                case 1:
                                    return 0.90F * scaleFactor;

                                case 2:
                                    return 0.90F * scaleFactor;

                                case 3:
                                    return 0.90F * scaleFactor;

                                case 4:
                                    return 0.90F * scaleFactor;

                                case 5:
                                    return 0.80F * scaleFactor;

                                default:
                                    return 0.90F * scaleFactor;
                            }
                        } else
                        {
                            switch (customRenderItem.getMiniItemCount(itemStack, (byte) 1))
                            {
                                case 1:
                                    return 0.65F * scaleFactor;

                                case 2:
                                    return 0.65F * scaleFactor;

                                case 3:
                                    return 0.65F * scaleFactor;

                                case 4:
                                    return 0.65F * scaleFactor;

                                default:
                                    return 0.65F * scaleFactor;
                            }
                        }
                    }

                    return scaleFactor;
                }

                private float getXDisplacementForSlot(int slot)
                {
                    switch (slot)
                    {
                        case 0:
                            return 0.0f;

                        case 1:
                            return -0.375f;

                        case 2:
                            return -0.125f;

                        case 3:
                            return 0.3125f;

                        case 4:
                            return 0.3125f;

                        case 5:
                            return -0.125f;

                        default:
                            return 0.0f;
                    }
                }

                private float getYDisplacementForSlot(int slot)
                {
                    switch (slot)
                    {
                        case 0:
                            return 0.4f;

                        case 1:
                            return -0.35f;

                        case 6:
                            return 0.4f;

                        default:
                            return -0.35f;
                    }
                }

                private float getZDisplacementForSlot(int slot)
                {
                    switch (slot)
                    {
                        case 0:
                            return 0.0f;

                        case 1:
                            return 0.0f;

                        case 2:
                            return 0.375f;

                        case 3:
                            return 0.25f;

                        case 4:
                            return -0.25f;

                        case 5:
                            return -0.375f;

                        default:
                            return 0.0f;
                    }
                }

                private void translateGhostItemByOrientation(ItemStack ghostItemStack, double x, double y, double z, ForgeDirection forgeDirection)
                {
                    if (ghostItemStack != null)
                    {
                        if (ghostItemStack.getItem() instanceof ItemBlock)
                        {
                            switch (forgeDirection)
                            {
                                case DOWN:
                                {
                                    GL11.glTranslatef((float) x + 0.5F, (float) y + 2.7F, (float) z + 0.5F);
                                    return;
                                }

                                case UP:
                                {
                                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.25F, (float) z + 0.5F);
                                    return;
                                }

                                case NORTH:
                                {
                                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.7F);
                                    return;
                                }

                                case SOUTH:
                                {
                                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.3F);
                                    return;
                                }

                                case EAST:
                                {
                                    GL11.glTranslatef((float) x + 0.3F, (float) y + 0.5F, (float) z + 0.5F);
                                    return;
                                }

                                case WEST:
                                {
                                    GL11.glTranslatef((float) x + 0.70F, (float) y + 0.5F, (float) z + 0.5F);
                                    return;
                                }

                                case UNKNOWN:
                                {
                                    return;
                                }

                                default:
                                {
                                    return;
                                }
                            }
                        } else
                        {
                            switch (forgeDirection)
                            {
                                case DOWN:
                                {
                                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.6F, (float) z + 0.5F);
                                    return;
                                }

                                case UP:
                                {
                                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.20F, (float) z + 0.5F);
                                    return;
                                }

                                case NORTH:
                                {
                                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.4F, (float) z + 0.7F);
                                    return;
                                }

                                case SOUTH:
                                {
                                    GL11.glTranslatef((float) x + 0.5F, (float) y + 0.4F, (float) z + 0.3F);
                                    return;
                                }

                                case EAST:
                                {
                                    GL11.glTranslatef((float) x + 0.3F, (float) y + 0.4F, (float) z + 0.5F);
                                    return;
                                }

                                case WEST:
                                {
                                    GL11.glTranslatef((float) x + 0.70F, (float) y + 0.4F, (float) z + 0.5F);
                                    return;
                                }

                                case UNKNOWN:
                                {
                                    return;
                                }

                                default:
                                {
                                    return;
                                }
                            }
                        }     
        

 

crash log:

[16:38:47] [Client thread/FATAL]: Reported exception thrown!
net.minecraft.util.ReportedException: Rendering Block Entity
at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.renderTileEntityAt(TileEntityRendererDispatcher.java:148) ~[TileEntityRendererDispatcher.class:?]
at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.renderTileEntity(TileEntityRendererDispatcher.java:126) ~[TileEntityRendererDispatcher.class:?]
at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:539) ~[RenderGlobal.class:?]
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1300) ~[EntityRenderer.class:?]
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1087) ~[EntityRenderer.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1057) ~[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.7.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_71]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_71]
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 net.minecraft.client.renderer.entity.RenderItem.getEntityTexture(RenderItem.java:245) ~[RenderItem.class:?]
at net.minecraft.client.renderer.entity.RenderItem.getEntityTexture(RenderItem.java:772) ~[RenderItem.class:?]
at net.minecraft.client.renderer.entity.Render.bindEntityTexture(Render.java:55) ~[Render.class:?]
at net.minecraft.client.renderer.entity.RenderItem.doRender(RenderItem.java:65) ~[RenderItem.class:?]
at com.baublelicious.blocks.TileentityPedistalRenderer.renderTileEntityAt(TileentityPedistalRenderer.java:86) ~[TileentityPedistalRenderer.class:?]
at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.renderTileEntityAt(TileEntityRendererDispatcher.java:141) ~[TileEntityRendererDispatcher.class:?]
... 15 more
[16:38:47] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----
// Hi. I'm Minecraft, and I'm a crashaholic.

Time: 31-12-14 16:38
Description: Rendering Block Entity

java.lang.NullPointerException: Rendering Block Entity
at net.minecraft.client.renderer.entity.RenderItem.getEntityTexture(RenderItem.java:245)
at net.minecraft.client.renderer.entity.RenderItem.getEntityTexture(RenderItem.java:772)
at net.minecraft.client.renderer.entity.Render.bindEntityTexture(Render.java:55)
at net.minecraft.client.renderer.entity.RenderItem.doRender(RenderItem.java:65)
at com.baublelicious.blocks.TileentityPedistalRenderer.renderTileEntityAt(TileentityPedistalRenderer.java:86)
at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.renderTileEntityAt(TileEntityRendererDispatcher.java:141)
at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.renderTileEntity(TileEntityRendererDispatcher.java:126)
at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:539)
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1300)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1087)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1057)
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(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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 net.minecraft.client.renderer.entity.RenderItem.getEntityTexture(RenderItem.java:245)
at net.minecraft.client.renderer.entity.RenderItem.getEntityTexture(RenderItem.java:772)
at net.minecraft.client.renderer.entity.Render.bindEntityTexture(Render.java:55)
at net.minecraft.client.renderer.entity.RenderItem.doRender(RenderItem.java:65)
at com.baublelicious.blocks.TileentityPedistalRenderer.renderTileEntityAt(TileentityPedistalRenderer.java:86)

-- Block Entity Details --
Details:
Name: TileentityPedistal // com.baublelicious.blocks.TileentityPedistalEntity
Block type: ID #205 (tile.PedistalBlock // com.baublelicious.blocks.TileentityPedistalBlock)
Block data value: 1 / 0x1 / 0b0001
Block location: World: (1435,4,-290), Chunk: (at 11,0,14 in 89,-19; contains blocks 1424,0,-304 to 1439,255,-289), Region: (2,-1; contains chunks 64,-32 to 95,-1, blocks 1024,0,-512 to 1535,255,-1)
Actual block type: ID #205 (tile.PedistalBlock // com.baublelicious.blocks.TileentityPedistalBlock)
Actual block data value: 1 / 0x1 / 0b0001
Stacktrace:
at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.renderTileEntityAt(TileEntityRendererDispatcher.java:141)
at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.renderTileEntity(TileEntityRendererDispatcher.java:126)
at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:539)
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1300)

Posted

Ok yeah, I am not sure what the problem is, but here's one thing:

EntityItem ghostEntityItem = new EntityItem(tileAltar.getWorldObj());

Don't do that.  You're creating a new entity every time the game renders the world.  Make it once, save it.

 

https://github.com/Draco18s/Artifacts/blob/master/main/java/com/draco18s/artifacts/client/ModelPedestal.java#L60-80

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Ok yeah, I am not sure what the problem is, but here's one thing:

EntityItem ghostEntityItem = new EntityItem(tileAltar.getWorldObj());

Don't do that.  You're creating a new entity every time the game renders the world.  Make it once, save it.

 

https://github.com/Draco18s/Artifacts/blob/master/main/java/com/draco18s/artifacts/client/ModelPedestal.java#L60-80

 

what then am i sepose to do = null or someting?

Posted

= null will get you nowhere.

As you can see, it's referencing the public property of the TileEntity.  Thus the value is handled by the TE thusly:

 

https://github.com/Draco18s/Artifacts/blob/master/main/java/com/draco18s/artifacts/entity/TileEntityDisplayPedestal.java#L236-249

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

In the code you have shared I do not see anything that would produce an NPE

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

What's at this line of the code?

at com.baublelicious.blocks.TileentityPedistalRenderer.renderTileEntityAt(TileentityPedistalRenderer.java:86) ~[TileentityPedistalRenderer.class:?]

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Put a breakpoint on that line and inspect the values. Either

customRenderItem

or

ghostEntityItem

is

null

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Put a breakpoint on that line and inspect the values. Either

customRenderItem

or

ghostEntityItem

is

null

.

and ghostEntityItem =

 

EntityItem['item.item.hoeDiamond'/31456, l='MpServer', x=0,00, y=0,00, z=0,00]

Posted

Um.  Yeah.  Don't do this:

customRenderItem = new RenderItem()

 

Just because you created an instance of that class doesn't mean that all of its properties are set.  The crash isn't happening in your code, it's happening inside RenderItem.  And what's null there? 

renderManager

.  Because creating a new RenderItem doesn't magically make that property defined.

 

Seriously:

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.