Jump to content

[Unsolved]Custom modeled block doesn't show up in inventory


TwinAndy

Recommended Posts

Two questions:

1: have you done .setUnlocalizedName("Mod:block.png") when you initialized the block?

2: did you use a tile entity in that block? if so what line did you put in your main mod file to register the renderer to the tile entity?

Two answers:

1: Yes

2:Yes

BlockFryer:

@Override
public TileEntity createNewTileEntity(World world) {

	return new TileEntityFryer();
}

Main:

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityFryer.class, new RenderFryer());

Link to comment
Share on other sites

Since you are using a custom rendering method for the block in the overworld, then you also need to use a custom rendering method for the block in other cases, such as in your inventory.

To do this, you need to create a IItemRenderer and register it for your block ID.

 

For example, in your new class that implements IItemRenderer:

public class FryerRenderer implements IItemRenderer {
@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) {
	switch(type) {
		case INVENTORY: {
			renderYourModel();
			return;
		}

		default: return;
	}
}

private void renderYourModel()
{
	// insert OpenGL code here....
}
}

 

Then, register it for your blockID in your mod class:

MinecraftForgeClient.registerItemRenderer(block_fryer.blockID, new FryerRenderer());

 

Hope I helped!

Link to comment
Share on other sites

Since you are using a custom rendering method for the block in the overworld, then you also need to use a custom rendering method for the block in other cases, such as in your inventory.

To do this, you need to create a IItemRenderer and register it for your block ID.

 

For example, in your new class that implements IItemRenderer:

public class FryerRenderer implements IItemRenderer {
@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) {
	switch(type) {
		case INVENTORY: {
			renderYourModel();
			return;
		}

		default: return;
	}
}

private void renderYourModel()
{
	// insert OpenGL code here....
}
}

 

Then, register it for your blockID in your mod class:

MinecraftForgeClient.registerItemRenderer(block_fryer.blockID, new FryerRenderer());

 

Hope I helped!

I don't know what you mean with insert opengl code

Sorry this is first time i made a custom modeled block

Link to comment
Share on other sites

-snip-

I don't know what you mean with insert opengl code

Sorry this is first time i made a custom modeled block

 

How are you rendering your "custom modeled block" then? Certainly there is some code you used. Did you use a wavefront (.obj)? Did you code it out yourself using those tedious openGL functions? Can you show me your class for rendering your tile entity? I kind of assumed that you already knew the rendering stuff; sorry if I confused you. I'll be able to help you if you show me your rendering code.

Link to comment
Share on other sites

-snip-

How are you rendering your "custom modeled block" then? Certainly there is some code you used. Did you use a wavefront (.obj)? Did you code it out yourself using those tedious openGL functions? Can you show me your class for rendering your tile entity? I kind of assumed that you already knew the rendering stuff; sorry if I confused you. I'll be able to help you if you show me your rendering code.

RenderFryer

package TwinAndysMods.SomeLittleThingsMod;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;

import org.lwjgl.opengl.GL11;
public class RenderFryer extends TileEntitySpecialRenderer
{
        public RenderFryer()
        {
                aModel = new ModelFryer();
        }

        public void renderAModelAt(TileEntityFryer tileentity1, double d, double d1, double d2, float f)
        {  
                GL11.glPushMatrix();
                GL11.glTranslatef((float)d + 0.5F, (float)d1 + 1.52F, (float)d2 + 0.5F);
                GL11.glRotatef(180F, 0F, 0F, 1F);
                bindTextureByName("/textures/blocks/FryerTexture.png");
                GL11.glPushMatrix();
                aModel.renderAll(0.0625F);
                GL11.glPopMatrix();     
                GL11.glPopMatrix();                                     
        }
        public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2,
                        float f)
        {
                renderAModelAt((TileEntityFryer)tileentity, d, d1, d2, f);
        }
        private ModelFryer aModel;
}



If you could help me i would love you (No homo)

Link to comment
Share on other sites

If you could help me i would love you (No homo)

 

How about just a simple "thank you"?  :P

 

Anyway, since you didn't provide the code for the model, I couldn't test it, so I just copied and pasted your code. (Like I expected you would have tried on your own...)

 

Add this to the FryerRenderer class I made for you.

private ModelFryer aModel;

public FryerRenderer()
{
    aModel = new ModelFryer();
}

...

private void renderYourModel()
{
    GL11.glPushMatrix();
    GL11.glTranslatef(0.0F, 0.0F, 0.0F); // play around with these numbers until you get it where you want it. (should work by itself)
    GL11.glRotatef(180F, 0F, 0F, 1F);
    bindTextureByName("/textures/blocks/FryerTexture.png");
    aModel.renderAll(0.0625F);
    GL11.glPopMatrix();
}

 

Also, I don't think you need to do two glPushMatrix()'s since you aren't doing anything special to your model between the second one and the first glPopMatrix(); one pair should be good enough.

Link to comment
Share on other sites

Also, I don't think you need to do two glPushMatrix()'s since you aren't doing anything special to your model between the second one and the first glPopMatrix(); one pair should be good enough.

 

definitely ^

 

you probably should rotate before you translate

 

doing translation before implies that you want to rotate according to the origin

 

 

aka if you have a boat at 0, 0

 

 

if you rotate then translate:

rotate: the boat faces left:

translate: the boat moves 10 unit

o = origin e = empty b = boat

rotate give

[d]  (for the sake of it well just imagine this is a rotation and now another letter

then translate:

[o][e][e][d]

 

if you translate then rotate:

translate, the boat is now 10 unit away

rotate: opengl rotates the origin, meaning

 

[o][e][e] would actually give  [o]

                                                    [e]

                                                    [e]

                                                   

nvm formating screwup up my ascii art

 

 

if you dont give a shit about why, or if i wasn't clear enough,

 

jsut switch glRotate and glTranslate order

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

If you could help me i would love you (No homo)

 

How about just a simple "thank you"?  :P

 

Anyway, since you didn't provide the code for the model, I couldn't test it, so I just copied and pasted your code. (Like I expected you would have tried on your own...)

 

Add this to the FryerRenderer class I made for you.

-snip-

 

Also, I don't think you need to do two glPushMatrix()'s since you aren't doing anything special to your model between the second one and the first glPopMatrix(); one pair should be good enough.

It doesn't work.

Im sorry that i didn't gave you a model.

ModelFryer

package TwinAndysMods.SomeLittleThingsMod;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelFryer extends ModelBase
{
  //fields
    ModelRenderer Shape1;
    ModelRenderer Shape2;
    ModelRenderer Shape3;
    ModelRenderer Shape4;
    ModelRenderer Shape5;
    ModelRenderer Shape6;
    ModelRenderer Shape7;
    ModelRenderer Shape8;
    ModelRenderer Shape9;
    ModelRenderer Shape10;
    ModelRenderer Shape11;
    ModelRenderer Shape12;
  
  public ModelFryer()
  {
    textureWidth = 64;
    textureHeight = 32;
    
      Shape1 = new ModelRenderer(this, 0, 0);
      Shape1.addBox(0F, 0F, 0F, 13, 1, 9);
      Shape1.setRotationPoint(-8F, 23F, -4F);
      Shape1.setTextureSize(64, 32);
      Shape1.mirror = true;
      setRotation(Shape1, 0F, 0F, 0F);
      Shape2 = new ModelRenderer(this, 0, 12);
      Shape2.addBox(0F, 0F, 0F, 1, 5, 9);
      Shape2.setRotationPoint(4F, 18F, -4F);
      Shape2.setTextureSize(64, 32);
      Shape2.mirror = true;
      setRotation(Shape2, 0F, 0F, 0F);
      Shape3 = new ModelRenderer(this, 44, 1);
      Shape3.addBox(0F, 0F, 0F, 1, 9, 9);
      Shape3.setRotationPoint(-8F, 14F, -4F);
      Shape3.setTextureSize(64, 32);
      Shape3.mirror = true;
      setRotation(Shape3, 0F, 0F, 0F);
      Shape4 = new ModelRenderer(this, 32, 26);
      Shape4.addBox(0F, 0F, 0F, 11, 5, 1);
      Shape4.setRotationPoint(-7F, 18F, 4F);
      Shape4.setTextureSize(64, 32);
      Shape4.mirror = true;
      setRotation(Shape4, 0F, 0F, 0F);
      Shape5 = new ModelRenderer(this, 32, 26);
      Shape5.addBox(0F, 0F, 0F, 11, 5, 1);
      Shape5.setRotationPoint(-7F, 18F, -4F);
      Shape5.setTextureSize(64, 32);
      Shape5.mirror = true;
      setRotation(Shape5, 0F, 0F, 0F);
      Shape6 = new ModelRenderer(this, 32, 19);
      Shape6.addBox(0F, 0F, 0F, 10, 1, 6);
      Shape6.setRotationPoint(-6.5F, 21F, -2.5F);
      Shape6.setTextureSize(64, 32);
      Shape6.mirror = true;
      setRotation(Shape6, 0F, 0F, 0F);
      Shape7 = new ModelRenderer(this, 0, 28);
      Shape7.addBox(0F, 0F, 0F, 10, 3, 1);
      Shape7.setRotationPoint(-6.5F, 18F, -2.5F);
      Shape7.setTextureSize(64, 32);
      Shape7.mirror = true;
      setRotation(Shape7, 0F, 0F, 0F);
      Shape8 = new ModelRenderer(this, 0, 28);
      Shape8.addBox(0F, 0F, 0F, 10, 3, 1);
      Shape8.setRotationPoint(-6.5F, 18F, 2.5F);
      Shape8.setTextureSize(64, 32);
      Shape8.mirror = true;
      setRotation(Shape8, 0F, 0F, 0F);
      Shape9 = new ModelRenderer(this, 22, 25);
      Shape9.addBox(0F, 0F, 0F, 1, 3, 4);
      Shape9.setRotationPoint(2.5F, 18F, -1.5F);
      Shape9.setTextureSize(64, 32);
      Shape9.mirror = true;
      setRotation(Shape9, 0F, 0F, 0F);
      Shape10 = new ModelRenderer(this, 22, 25);
      Shape10.addBox(0F, 0F, 0F, 1, 3, 4);
      Shape10.setRotationPoint(-6.5F, 18F, -1.5F);
      Shape10.setTextureSize(64, 32);
      Shape10.mirror = true;
      setRotation(Shape10, 0F, 0F, 0F);
      Shape11 = new ModelRenderer(this, 13, 11);
      Shape11.addBox(0F, 0F, 0F, 11, 0, 7);
      Shape11.setRotationPoint(-7F, 19F, -3F);
      Shape11.setTextureSize(64, 32);
      Shape11.mirror = true;
      setRotation(Shape11, 0F, 0F, 0F);
      Shape12 = new ModelRenderer(this, 0, 26);
      Shape12.addBox(0F, 0F, 0F, 6, 1, 1);
      Shape12.setRotationPoint(2.5F, 17F, 0F);
      Shape12.setTextureSize(64, 32);
      Shape12.mirror = true;
      setRotation(Shape12, 0F, 0F, 0F);
  }
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5);
    Shape1.render(f5);
    Shape2.render(f5);
    Shape3.render(f5);
    Shape4.render(f5);
    Shape5.render(f5);
    Shape6.render(f5);
    Shape7.render(f5);
    Shape8.render(f5);
    Shape9.render(f5);
    Shape10.render(f5);
    Shape11.render(f5);
    Shape12.render(f5);
  }
  public void renderAll(float f5){
  Shape1.render(f5);
    Shape2.render(f5);
    Shape3.render(f5);
    Shape4.render(f5);
    Shape5.render(f5);
    Shape6.render(f5);
    Shape7.render(f5);
    Shape8.render(f5);
    Shape9.render(f5);
    Shape10.render(f5);
    Shape11.render(f5);
    Shape12.render(f5);

  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5)
  {
    
  }

}

FryerRenderer

package TwinAndysMods.SomeLittleThingsMod;

import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

public class FryerRenderer implements IItemRenderer {
@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) {
	switch(type) {
		case INVENTORY: {
			renderModelFryer();
			return;
		}

		default: return;
	}
}


private ModelFryer aModel;

public FryerRenderer()
{
    aModel = new ModelFryer();
}


private void renderModelFryer()
{
    GL11.glPushMatrix();
    GL11.glTranslatef(0.0F, 0.0F, 0.0F); // play around with these numbers until you get it where you want it. (should work by itself)
    GL11.glRotatef(180F, 0F, 0F, 1F);
    bindTextureByName("/textures/blocks/FryerTexture.png");
    aModel.renderAll(0.0625F);
    GL11.glPopMatrix();
}

private void bindTextureByName(String string) {


}
}

I think i did something wron with the bindTextureByName....

I already gave you a thank you but if you still want to help me out a bit.

Link to comment
Share on other sites

If you could help me i would love you (No homo)

 

How about just a simple "thank you"?  :P

 

Anyway, since you didn't provide the code for the model, I couldn't test it, so I just copied and pasted your code. (Like I expected you would have tried on your own...)

 

Add this to the FryerRenderer class I made for you.

-snip-

 

Also, I don't think you need to do two glPushMatrix()'s since you aren't doing anything special to your model between the second one and the first glPopMatrix(); one pair should be good enough.

It doesn't work.

Im sorry that i didn't gave you a model.

ModelFryer

package TwinAndysMods.SomeLittleThingsMod;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelFryer extends ModelBase
{
  //fields
    ModelRenderer Shape1;
    ModelRenderer Shape2;
    ModelRenderer Shape3;
    ModelRenderer Shape4;
    ModelRenderer Shape5;
    ModelRenderer Shape6;
    ModelRenderer Shape7;
    ModelRenderer Shape8;
    ModelRenderer Shape9;
    ModelRenderer Shape10;
    ModelRenderer Shape11;
    ModelRenderer Shape12;
  
  public ModelFryer()
  {
    textureWidth = 64;
    textureHeight = 32;
    
      Shape1 = new ModelRenderer(this, 0, 0);
      Shape1.addBox(0F, 0F, 0F, 13, 1, 9);
      Shape1.setRotationPoint(-8F, 23F, -4F);
      Shape1.setTextureSize(64, 32);
      Shape1.mirror = true;
      setRotation(Shape1, 0F, 0F, 0F);
      Shape2 = new ModelRenderer(this, 0, 12);
      Shape2.addBox(0F, 0F, 0F, 1, 5, 9);
      Shape2.setRotationPoint(4F, 18F, -4F);
      Shape2.setTextureSize(64, 32);
      Shape2.mirror = true;
      setRotation(Shape2, 0F, 0F, 0F);
      Shape3 = new ModelRenderer(this, 44, 1);
      Shape3.addBox(0F, 0F, 0F, 1, 9, 9);
      Shape3.setRotationPoint(-8F, 14F, -4F);
      Shape3.setTextureSize(64, 32);
      Shape3.mirror = true;
      setRotation(Shape3, 0F, 0F, 0F);
      Shape4 = new ModelRenderer(this, 32, 26);
      Shape4.addBox(0F, 0F, 0F, 11, 5, 1);
      Shape4.setRotationPoint(-7F, 18F, 4F);
      Shape4.setTextureSize(64, 32);
      Shape4.mirror = true;
      setRotation(Shape4, 0F, 0F, 0F);
      Shape5 = new ModelRenderer(this, 32, 26);
      Shape5.addBox(0F, 0F, 0F, 11, 5, 1);
      Shape5.setRotationPoint(-7F, 18F, -4F);
      Shape5.setTextureSize(64, 32);
      Shape5.mirror = true;
      setRotation(Shape5, 0F, 0F, 0F);
      Shape6 = new ModelRenderer(this, 32, 19);
      Shape6.addBox(0F, 0F, 0F, 10, 1, 6);
      Shape6.setRotationPoint(-6.5F, 21F, -2.5F);
      Shape6.setTextureSize(64, 32);
      Shape6.mirror = true;
      setRotation(Shape6, 0F, 0F, 0F);
      Shape7 = new ModelRenderer(this, 0, 28);
      Shape7.addBox(0F, 0F, 0F, 10, 3, 1);
      Shape7.setRotationPoint(-6.5F, 18F, -2.5F);
      Shape7.setTextureSize(64, 32);
      Shape7.mirror = true;
      setRotation(Shape7, 0F, 0F, 0F);
      Shape8 = new ModelRenderer(this, 0, 28);
      Shape8.addBox(0F, 0F, 0F, 10, 3, 1);
      Shape8.setRotationPoint(-6.5F, 18F, 2.5F);
      Shape8.setTextureSize(64, 32);
      Shape8.mirror = true;
      setRotation(Shape8, 0F, 0F, 0F);
      Shape9 = new ModelRenderer(this, 22, 25);
      Shape9.addBox(0F, 0F, 0F, 1, 3, 4);
      Shape9.setRotationPoint(2.5F, 18F, -1.5F);
      Shape9.setTextureSize(64, 32);
      Shape9.mirror = true;
      setRotation(Shape9, 0F, 0F, 0F);
      Shape10 = new ModelRenderer(this, 22, 25);
      Shape10.addBox(0F, 0F, 0F, 1, 3, 4);
      Shape10.setRotationPoint(-6.5F, 18F, -1.5F);
      Shape10.setTextureSize(64, 32);
      Shape10.mirror = true;
      setRotation(Shape10, 0F, 0F, 0F);
      Shape11 = new ModelRenderer(this, 13, 11);
      Shape11.addBox(0F, 0F, 0F, 11, 0, 7);
      Shape11.setRotationPoint(-7F, 19F, -3F);
      Shape11.setTextureSize(64, 32);
      Shape11.mirror = true;
      setRotation(Shape11, 0F, 0F, 0F);
      Shape12 = new ModelRenderer(this, 0, 26);
      Shape12.addBox(0F, 0F, 0F, 6, 1, 1);
      Shape12.setRotationPoint(2.5F, 17F, 0F);
      Shape12.setTextureSize(64, 32);
      Shape12.mirror = true;
      setRotation(Shape12, 0F, 0F, 0F);
  }
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5);
    Shape1.render(f5);
    Shape2.render(f5);
    Shape3.render(f5);
    Shape4.render(f5);
    Shape5.render(f5);
    Shape6.render(f5);
    Shape7.render(f5);
    Shape8.render(f5);
    Shape9.render(f5);
    Shape10.render(f5);
    Shape11.render(f5);
    Shape12.render(f5);
  }
  public void renderAll(float f5){
  Shape1.render(f5);
    Shape2.render(f5);
    Shape3.render(f5);
    Shape4.render(f5);
    Shape5.render(f5);
    Shape6.render(f5);
    Shape7.render(f5);
    Shape8.render(f5);
    Shape9.render(f5);
    Shape10.render(f5);
    Shape11.render(f5);
    Shape12.render(f5);

  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5)
  {
    
  }

}

FryerRenderer

package TwinAndysMods.SomeLittleThingsMod;

import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

public class FryerRenderer implements IItemRenderer {
@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) {
	switch(type) {
		case INVENTORY: {
			renderModelFryer();
			return;
		}

		default: return;
	}
}


private ModelFryer aModel;

public FryerRenderer()
{
    aModel = new ModelFryer();
}


private void renderModelFryer()
{
    GL11.glPushMatrix();
    GL11.glTranslatef(0.0F, 0.0F, 0.0F); // play around with these numbers until you get it where you want it. (should work by itself)
    GL11.glRotatef(180F, 0F, 0F, 1F);
    bindTextureByName("/textures/blocks/FryerTexture.png");
    aModel.renderAll(0.0625F);
    GL11.glPopMatrix();
}

private void bindTextureByName(String string) {


}
}

I think i did something wron with the bindTextureByName....

I already gave you a thank you but if you still want to help me out a bit.

I'll daresay you did. This probably isn't right, but try Minecraft.theMinecraft.renderEngine.bindTexture("..."); instead.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

I'll daresay you did. This probably isn't right, but try Minecraft.theMinecraft.renderEngine.bindTexture("..."); instead.

Minecraft.theMinecraft.renderEngine.bindTexture("/textures/blocks/FryerTexture.png");

I get an error under theMinecraft

Link to comment
Share on other sites

So

bindTextureByName("/textures/blocks/FryerTexture.png");

In this code you need to place your model texture into the minecraft.jar/textures/block

So, you need this, If you want to have your texture in diff location:

bindTextureByName("mods/YOURMODID/textures/blocks/FryerTexture.png");

And your modid is Mod´s modid, defined in main class of mod.

This will allow you to place the texture into the minecraft.jar/mods/YOURMODID/textures/block

Try, and write back! Good luck with your mod  :)

Check out my m2cAPI: http://pastebin.com/SJmjgdgK [WIP! If something doesnt work or you have a better resolution, write me a PM]

If you want to use my API please give me a Karma/Thank you

Sorry for some bad words ´cause I am not a walkin´ library!

Link to comment
Share on other sites

-snip-

Try, and write back! Good luck with your mod  :)

I do have my textures in textures/blocks but the model doesn't show up in my inventory...

 

Ok let me help you out with this quickly because it's easy enough if you know where what goes

 

Now we are assuming the following;

 

1) You are using a model ingame

2) You manage to render the model ingame

3) You haven't manage to render the model in your hand while holding it.

 

Now another way to do this one used by many was to create a normal item then register that item and use the item to place the model, this off course is a lot more work for something you can easily obtain by usng the following methods.

 

Drop your render file as it is atm as in completely and create a new one that should look like this

 

public class FryerRenderer extends TileEntitySpecialRenderer
{
    private ModelFryer aModel = new ModelFryer();

    public void renderAModel(TileEntityFryer var1, double var2, double var4, double var6, float var8)
    {
    	
        int i1 = 0;

        if (var1.worldObj != null)
        {
            i1 = var1.getBlockMetadata();
        }
    	
    	
        int var9;

        if (var1.worldObj == null)
        {
            var9 = 0;
        }
        else
        {
            Block var10 = var1.getBlockType();
            var9 = var1.getBlockMetadata();

            if (var10 != null && var9 == 0)
            {
                var9 = var1.getBlockMetadata();
            }
        }

        GL11.glPushMatrix();
        GL11.glTranslatef((float)var2 + 0.5F, (float)var4 + 1.5F, (float)var6 + 0.5F);
        short var11 = 0;

        if (var9 == 3)
        {
            var11 = 90;
        }

        if (var9 == 2)
        {
            var11 = 180;
        }

        if (var9 == 1)
        {
            var11 = 270;
        }

        GL11.glRotatef((float)var11, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
        this.bindTextureByName("/textures/blocks/FryerTexture.png");
        GL11.glPushMatrix();
        this.aModel.renderModel(0.0625F);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
    }

    public void renderTileEntityAt(TileEntity var1, double var2, double var4, double var6, float var8)
    {
        this.renderAModel((TileEntityFryer)var1, var2, var4, var6, var8);
    }
    

}

 

So instead of implementing ItemRenderer you implement TileEntitySpecialRenderer, for your tile entity you just need a file that can basically be empty something like this

 

public class TileEntityFryer extends TileEntity
{
}

 

Off course if your model has special function it would be in the tileentity so it will look a bit different.

 

Your model file is fine no changes needed their, the method that will be rendering your item for you is inside the render file this bit public void renderTileEntityAt, this is also used to render the model in game so the results would be that whatever you place in world would render in your hands and also in the inventory

 

The last bit of info you need to make sure you have is the registering part;

 

Now depending on how you go about registering your model the code should be like below I basically call my model registering from another class because i have over 30+ models in game and I use my clientproxy to register the model in cause you mostly need this to be client side only it will look something like this;

 

RenderingRegistry.registerBlockHandler(FryerID,new RenderInv());
FryerID = RenderingRegistry.getNextAvailableRenderId();

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityFryer.class, new FryerRenderer());

 

then the following need to be register inside your proxy i basicly have thsi inside my client proxy and proxy just to make double sure it gets registered

 

GameRegistry.registerTileEntity(TileEntityFryer.class, "TileEntityFryer");

 

Now this code can be place anywhere as long as it's executed at runtime or while registering takes place.

 

just import all your class files you need and then you wil have to create the following class file you can call it anything you like actually I call mine RenderInv and this is where I would tell my model where and how to render the item in hand the code will look like this

 

public class RenderInv  implements ISimpleBlockRenderingHandler
{

public void renderInventoryBlock(Block block, int metadata, int modelID,
		RenderBlocks renderer) {

        if (block == BlockFryer)
        {
         TileEntityRenderer.instance.renderTileEntityAt(new TileEntityFryer(), 0.0D, 0.0D, 0.0D, 0.0F);
        }

}

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z,
		Block block, int modelId, RenderBlocks renderer) {
	return false;
}

public boolean shouldRender3DInInventory() {
	return true;
}

public int getRenderId() {
	return 0;
}

}

 

That's basically all you need to see your model in your hand, without the need to add an extra item into the game this will take your 3d model and create a 3d model for you that you can hold it in your hand. All you now need to do is take this code and implement it into your project the RenderInv can be expanded later on to include all your models inventory items and off course you need to make sure everything is imported and pointing towards the right class file names.

 

Happy coding...

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.