Jump to content

[Solved] How to properly add an Item for a Block that renders block-style?


Two

Recommended Posts

Hi everyone,

 

I am currently trying to add a new block - a lava tank - that keeps the fuel amount when picked up. So far I have been successful with almost everything, except for properly creating an item that tracks the fuel limit but is rendered as the block at the same time. I can obviously write my own renderer, but why do that if one already exists and is much more upward-compatible?

 

What I have tried so far:

  • My first attempt was to use the ItemBlockWithMetadata item, which works except for the inaccurate storage, but Forge complains that this anonymous item class will not survive a 1.7 update.
  • I tried to create my own ItemBlock sub-class, which works fine, except that the item is now rendered flat instead of the 3d block look.
  • I tried to use ItemBlockWithMetadata and register it with the block, but now Forge obviously complains that I am overwriting an existing block.

 

Could someone please give me a hint how I can do this properly, or if possible a short tutorial (for experienced programmers)?

 

Thanks in advance!

 

Edit: Thanks to Draco18s this was solved in the following way:

[*]Created a sub-class of ItemBlockWithMetadata that forwards getIcon(side, metadata) to the same block function

[*]Added a new renderer. (Basically a copy of this tutorial)

[*]Registered item with renderer in ProxyClient:

  itemRendererBlock3d = new ItemRendererBlock3d();
  MinecraftForgeClient.registerItemRenderer(itemLavaTank.itemID, itemRendererBlock3d);

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

Link to comment
Share on other sites

Look at ItemRedstone and BlockRedstoneWire

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.

Link to comment
Share on other sites

Look at ItemRedstone and BlockRedstoneWire

 

I am not sure how this is supposed to help me. The Redstone ore/wire renders as an item in the inventory and not as a block. This is what I already got with my 2nd attempt, but I do want the icon in the inventory to render as the 3D-block.

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

Link to comment
Share on other sites

Ah, rendering problem.

 

You need a custom IItemRenderer

 

Here's an example:

 

public class ItemRenderPedestal implements IItemRenderer {
TileEntitySpecialRenderer render;
private TileEntity dummytile;
  
public ItemRenderPedestal(TileEntitySpecialRenderer render, TileEntity dummy) {
    this.render = render;
    this.dummytile = dummy;
}

@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.dummytile, 0.0D, 0.0D, 0.0D, 0.0F);
}
}

 

And client prox registration:

 

		TileEntitySpecialRenderer render = new PedestalRenderer();
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDisplayPedestal.class, render);
        MinecraftForgeClient.registerItemRenderer(BlockPedestal.instance.blockID, new ItemRenderPedestal(render, new TileEntityDisplayPedestal()));

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.

Link to comment
Share on other sites

Ah, rendering problem.

 

You need a custom IItemRenderer

 

Just before I start some probably unnecessary work: If I understand you correctly, I need to implement my own renderer to get a block to render like a block, and there is no way I can use the already existing rendering code for blocks from Minecraft (except for copy&paste), just because I must use my own item so the block retains the meta value if dropped, correct?

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

Link to comment
Share on other sites

Because your inventory item is of Class Item, you need to implement an IItemRenderer to override the default 2D item renderer.

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.

Link to comment
Share on other sites

Its not hard.  Annoying sure, but not hard.

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.

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



×
×
  • Create New...

Important Information

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