Jump to content

[SOLVED]Inventory render custom model block


xGamer_Allx

Recommended Posts

SOLVED REMAKING IT WITH A MODEL IN OBJ AND MODIFY THE METHODS

Hello all, I make a custom block with a model created with techne.

It work (the texture of the block into the game world see) but into inventory it not have a texture...

My situation is similar to the chest: the texture of the block is into "assets/mymod/textures/entity/texture.png"

 

How can I apply the texture of the world into the inventory also? (What'is the metod, and if you can make a example of it)

 

Thanks

Link to comment
Share on other sites

That took me while to figure out  but now that I know it its easy

 

first you need an Item render class for it such as this

 

Disclaimer: this works for blocks, may or may not work for items

 

itemcomputerrenderer

package kakarotvg.omega.render.itemrender;

import kakarotvg.omega.entity.tileentity.TileEntityComputerEntity;
import kakarotvg.omega.model.ModelComputer;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;

public class ItemComputerRenderer implements IItemRenderer {

    private ModelComputer computermodel;

    public ItemComputerRenderer() {
        computermodel = new ModelComputer();
    }

    @Override
    public boolean handleRenderType(ItemStack item, ItemRenderType type) {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
        TileEntityRenderer.instance.renderTileEntityAt(new TileEntityComputerEntity(), 0.0D, 0.0D, 0.0D, 0.0f);
    }

}

 

then you need to register the item renderer in your client proxy

package kakarotvg.omega.proxys;

import kakarotvg.omega.entity.mobs.EntityAnnihilator;
import kakarotvg.omega.entity.mobs.EntityEliminator;
import kakarotvg.omega.entity.mobs.EntityJungleAssasin;
import kakarotvg.omega.entity.mobs.EntityOmegaHound;
import kakarotvg.omega.entity.mobs.EntityOmegakiller;
import kakarotvg.omega.entity.mobs.EntitySlayer;
import kakarotvg.omega.entity.tileentity.TileEntityComputerEntity;
import kakarotvg.omega.entity.tileentity.TileEntityDarknessSolidEntity;
import kakarotvg.omega.handlers.tileentity.TileEntityHandler;
import kakarotvg.omega.model.ModelAnnihilator;
import kakarotvg.omega.model.ModelEliminator;
import kakarotvg.omega.model.ModelJungleAsasin;
import kakarotvg.omega.model.ModelOmegaHound;
import kakarotvg.omega.model.ModelOmegakiller;
import kakarotvg.omega.model.ModelSlayer;
import kakarotvg.omega.render.itemrender.ItemComputerRenderer;
import kakarotvg.omega.render.itemrender.UnderworldChestItemRender;
import kakarotvg.omega.render.mobs.RenderAnnihilator;
import kakarotvg.omega.render.mobs.RenderEliminator;
import kakarotvg.omega.render.mobs.RenderJungleAssasin;
import kakarotvg.omega.render.mobs.RenderOmegaHound;
import kakarotvg.omega.render.mobs.RenderOmegaKiller;
import kakarotvg.omega.render.mobs.RenderSlayer;
import kakarotvg.omega.render.tileentity.TileEntityComputerRenderer;
import kakarotvg.omega.render.tileentity.TileEntityDarknessSolidRenderer;
import kakarotvg.omega.render.tileentity.TileEntityUnderworldchestrenderer;
import kakarotvg.omega.tileentity.TileEntityUnderworldChest;
import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;

public class ClientProxy extends CommonProxy {

    public void registerRenderInformation() {
        // Renders the Mobs
        RenderingRegistry.registerEntityRenderingHandler(EntityOmegaHound.class, new RenderOmegaHound(new ModelOmegaHound(), 0.05F));
        RenderingRegistry.registerEntityRenderingHandler(EntityOmegakiller.class, new RenderOmegaKiller(new ModelOmegakiller(), 0.5F));
        RenderingRegistry.registerEntityRenderingHandler(EntityEliminator.class, new RenderEliminator(new ModelEliminator(), 0.5F));
        RenderingRegistry.registerEntityRenderingHandler(EntitySlayer.class, new RenderSlayer(new ModelSlayer(), 0.5F));
        RenderingRegistry.registerEntityRenderingHandler(EntityAnnihilator.class, new RenderAnnihilator(new ModelAnnihilator(), 0.5F));
        RenderingRegistry.registerEntityRenderingHandler(EntityJungleAssasin.class, new RenderJungleAssasin(new ModelJungleAsasin(), 0.5F));
    }

    public void registerRenderThings() {
        ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDarknessSolidEntity.class, new TileEntityDarknessSolidRenderer());
        ClientRegistry.bindTileEntitySpecialRenderer(TileEntityComputerEntity.class, new TileEntityComputerRenderer());
        ClientRegistry.bindTileEntitySpecialRenderer(TileEntityUnderworldChest.class, new TileEntityUnderworldchestrenderer());
        // the item renderers
        MinecraftForgeClient.registerItemRenderer(TileEntityHandler.underworldchest.blockID, new UnderworldChestItemRender());
        MinecraftForgeClient.registerItemRenderer(TileEntityHandler.computer.blockID, new ItemComputerRenderer());
    }

    @Override
    public void registerRenders() {

    }

    @Override
    public int addArmor(String armor) {
        return RenderingRegistry.addNewArmourRendererPrefix(armor);
    }

}

 

then you need to make sure that if your block rotates based on your direction when placing it.

then you have to have an if else statement for the world

package kakarotvg.omega.render.tileentity;

import kakarotvg.omega.Reference;
import kakarotvg.omega.model.ModelComputer;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class TileEntityComputerRenderer extends TileEntitySpecialRenderer {

    //The model of your block
    public final ModelComputer model;
    private static final ResourceLocation resourceloc = new ResourceLocation(Reference.MOD_ID + ":" + "textures/tileentity/computer.png");

    public TileEntityComputerRenderer() {
        this.model = new ModelComputer();
    }

    @Override
    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
        //The PushMatrix tells the renderer to "start" doing something.
        GL11.glPushMatrix();

        //This is setting the initial location.
        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        //This is the texture of your block. It's pathed to be the same place as your other blocks here.
        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!    
        Minecraft.getMinecraft().renderEngine.func_110577_a(resourceloc);
        GL11.glPushMatrix();
        GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

        adjustLightFixture(te.worldObj, te.xCoord, te.yCoord, te.zCoord, te.blockType);

        //A reference to your Model file. Again, very important.
        //Tell it to stop rendering for both the PushMatrix's
        GL11.glPopMatrix();
        GL11.glPopMatrix();
    }

    //Set the lighting stuff, so it changes it's brightness properly.       
    private void adjustLightFixture(World world, int i, int j, int k, Block block) {
        //  the if statement checking for if the world is null or not if not renders the block if null renders the item model
        // != means not equal
        if (world != null) {
            int dir = world.getBlockMetadata(i, j, k);

            GL11.glPushMatrix();
            //This line actually rotates the renderer.
            GL11.glRotatef(dir * (90F), 0F, 1F, 0F);

            this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
            /*
             * Place your rendering code here.
             */

            GL11.glPopMatrix();
        }
        else {
            GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
            this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        }

    }
}

if (You.likescoding == false){
      You.goaway;
}

Link to comment
Share on other sites

in your class add this code

public static final ResourceLocation TEXTURE = new ResourceLocation("mymod", "textures/entity/texture.png");

and add this to your item renderers render method after the GL11.glDisable line and after the GL11.glTranslate line

FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);

and just leave the TEXTURE as TEXTURE, its referencing the ResourceLocation. If that doesn't work toy with it.

Link to comment
Share on other sites

I just tried the

 

FMLClientHandler.instance().getClient().renderEngine.bindtexture(TEXTURE);

 

in my mod and it could not find bindtexture but this worked

 

FMLClientHandler.instance().getClient().renderEngine.func_110577_a(resourceloc);

if (You.likescoding == false){
      You.goaway;
}

Link to comment
Share on other sites

Ok Place my code maybe it help more:

 

 

public class mod_test {

@SidedProxy(blabla)

    public static CommonProxy proxy;

@Instance(value = Logic.MOD_ID)

    public static mod_test instance;

private GuiHandlerTestTable guiHandlerTestTable = new GuiHandlerTestTable();

public static CreativeTabs TestModBlocks = new CreativeTabsTestBlocks(CreativeTabs.getNextID(), "BlocksTestTab", "Test Mod Blocks Tab");

//Blocks

public static Block TestTable;

//BlockID

public static int TestTableID;

@EventHandler

    public void preInit(FMLPreInitializationEvent event) {

TestBlockManager();

TestBlockRegistry();

    }

 

@EventHandler

    public void load(FMLInitializationEvent event) {

proxy.registerRenderers();

    }

@EventHandler

    public void postInit(FMLPostInitializationEvent event) {

   

    }

   

    private void TestBlockManager() {

    Table = new BlocTestkProjectTableTestTableID, TileEntityTestTable.class, Material.wood).setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundWoodFootstep).setUnlocalizedName("testbench").setCreativeTab(TestModBlocks);

    }

   

    private void TestBlockRegistry() {

    //Registry

    GameRegistry.registerBlock(TestTable, TestTable.getUnlocalizedName());{

    //Names

    LanguageRegistry.addName(TestTable, "Test Table");

}

 

 

BlockClass:

 

 

private Class TileEntityClass;

 

public BlockTestTable(int i,Class tClass, Material par3Material)

  {

        super(i, par3Material);

        TileEntityClass = tClass;

          float f = 0F;

          setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.05F, 1.0F);

  }

 

@Override

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int i, float f, float g, float t)

{

    TileEntity tile_entity = world.getBlockTileEntity(x, y, z);

   

            if(tile_entity == null || player.isSneaking()){

            return false;

            }

 

    player.openGui(mod_test.instance, 0, world, x, y, z);

    return true;

    }

 

 

@Override

public void breakBlock(World world, int x, int y, int z, int i, int j)

{

    super.breakBlock(world, x, y, z, i, j);

    }

 

 

        public TileEntity getBlockEntity()

        {

                        try{

                                        return (TileEntity)TileEntityClass.newInstance();

                        }

                        catch(Exception exception){

                                        throw new RuntimeException(exception);

                        }

        }

 

        public int idDropped(int i, Random random, int j)

        {

                return this.blockID;

        }

 

       

        public int quanityDropped(Random random)

        {

          return 1;

        }

 

        @Override

        public int getRenderType()

        {

        return ClientProxy.BlockTestTableRenderID;

        }

 

        public boolean isOpaqueCube()

        {

                return false;

        }

 

        public boolean renderAsNormalBlock()

        {

                return false;

        }

public TileEntity createNewTileEntity(World world)

{

  return new TileEntityTestTable();

 

}

}

 

 

TileEntityTestTable:

 

 

 

This is for the gui not need code;

 

 

 

TileEntityRender:

 

 

 

public class TileEntityTestTableRenderer extends TileEntitySpecialRenderer

{

public static final ResourceLocation testTableLoc = new ResourceLocation (Logic.MOD_IDFOLDER + ":" + "textures/entity/test_tabletest_table.png");

        public TileEntityTestTableRenderer()

        {

                aModel = new TestTableModel();

        }

 

        public void renderAModelAt(TileEntityTestTable 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);

                FMLClientHandler.instance().getClient().renderEngine.bindTexture(testTableLoc);

                GL11.glRotatef(180F, 0F, 0F, 1F);

                bindTexture(testTableLoc);

                GL11.glPushMatrix();

                aModel.renderModel(0.0625F);

                GL11.glPopMatrix();   

                GL11.glPopMatrix();                                   

        }

        public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2,

                        float f)

        {

                renderAModelAt((TileEntityTestTable)tileentity, d, d1, d2, f);

        }

        private TestTableModel aModel;

}

 

 

 

 

client proxy:

 

 

public class ClientProxy extends CommonProxy {

 

public static int BlockTestTableRenderID;

 

@Override

    public void registerRenderers() {

BlockTestTableRenderID = RenderingRegistry.getNextAvailableRenderId();

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTestTable.class, new TileEntityTestTableRenderer());

}

 

 

 

1)How can I render my model into inventory?

2)How can I render the texture file into the inventory?

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.