Jump to content

Item Rendering Doesn't Work with Direction


Whyneb360

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Slot deposit 3000 adalah situs slot deposit 3000 via dana yang super gacor dimana para pemain dijamin garansi wd hari ini juga hanya dengan modal receh berupa deposit sebesar 3000 baik via dana, ovo, gopay maupun linkaja untuk para pemain pengguna e-wallet di seluruh Indonesia.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT 3000 ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI <a href="https://imgbb.com/"><img src="https://i.ibb.co/GnjSVpx/daftar1-480x480.webp" alt="daftar1-480x480" border="0" /></a> Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit pulsa adalah situs slot deposit pulsa tanpa potongan apapun yang dijamin garansi terpercaya, dimana kamu bisa bermain slot dengan melakukan deposit pulsa dan tanpa dikenakan potongan apapun sehingga dana yang masuk ke dalam akun akan 100% utuh. Proses penarikan dana juga dijamin gampang dan tidak sulit sehingga kamu tidak perlu khawatir akan kemenangan yang akan kamu peroleh dengan sangat mudah jika bermain disini.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT PULSA TANPA POTONGAN ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

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