Jump to content

[INSANE]TileEntities/Rendering/NBT problems


mar21

Recommended Posts

Hello, I know I can search on YT or Google, but I didnt found any (about TileEntities and their usage).

Can anyone tell me some basic informations about: What TE doing, what things you can do with them, etc...

Or if you know a hyperlink to a good tutorial, you can write the link there  ;)

 

Reason: I am currently doing on a Energy Site in my mod. I need TE to do some hard stuff.

Like:

If there is a block on the any of the 6 sides, check if the block can store energy. If yes send energy to him if the main block have extra energy. If no, it is full of energy. If have the main block space, consume the energy from the block and etc.

 

 

Thanks very much!

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

Yes hydroflame, but the tutorial dont tell me what things I can do with tile entities. But I give you good karma :D

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

ah ok

 

generic description: tile entities are used to store any extra information that wont fit in the metadata (aka a number between 0-15)

 

vanilla blocks that use tile entities(TE): sign, store the text to be displayed, chest, store  if if or not the chest is opened by someone, beacon, store how many buff are available and if its active.

 

random idea i have at 6am just woke up: statue that holds buff that player can get and recover them periodically, 2 way teleporter, slot machine, bank

 

for more exemple look at almost any mod on github.

 

-hydroflame, FRev-

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Ok, so. I created a this things in My Tile Entity and My Block Class. How I can "run" this things. It dont do anything.

BLOCK CLASS:

 

package mar21.omega.machine;

 

import java.util.Random;

 

import mar21.omega.ModCore;

import mar21.omega.machine.tileEntity.TileEntityPowerConduit;

import mar21.omega.mar21.Mar21Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

 

public class MachinePowerConduit extends Mar21Block

{

    private final Random powerRand = new Random();

    public static int powerTick;

 

 

    public MachinePowerConduit(int id, Material par2Material, CreativeTabs par3CreativeTabs)

    {

    super(id, par2Material, par3CreativeTabs);

    this.setHardness(2.0F);

    }

 

    public int idDropped(int par1, Random par2Random, int par3)

    {

        return ModCore.power_conduit.blockID;

    }

   

    public TileEntity createTileEntity(World world, int metadata)

    {

    return new TileEntityPowerConduit();

    }

   

    public void onBlockAdded(World par1World, int par2, int par3, int par4)

    {

        super.onBlockAdded(par1World, par2, par3, par4);

        par1World.scheduleBlockUpdate(par2, par3, par4, ModCore.power_conduit.blockID, 5);

    }

   

@Override

public void updateTick(World world, int x,int y, int z, Random rand)

{

    super.updateTick(world, x, y, z, rand);

    world.scheduleBlockUpdate(x, y, z, ModCore.power_conduit.blockID, 5);

}

}

 

 

TILEENTITYCLASS:

 

package mar21.omega.machine.tileEntity;

 

import java.util.Random;

 

import mar21.omega.ModCore;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

 

public class TileEntityPowerConduit extends TileEntity

{

public int EnergyStored;

public int maxEnergyStored;

public int sendEnergyPacket;

public boolean canSendEnergy;

public boolean canReceiveEnergy;

public World par1World;

public int i,j,k;

public boolean side1,side2,side3,side4,side5,side6;

 

@Override

public void writeToNBT(NBTTagCompound par1)

{

super.writeToNBT(par1);

par1.setInteger("EnergyStored", EnergyStored);

}

@Override

public void readFromNBT(NBTTagCompound par1)

{

super.readFromNBT(par1);

this.EnergyStored = par1.getInteger("EnergyStored");

}

public boolean checkBlockOnSide(int i, int j, int k)

{

par1World = this.worldObj;

if(ModCore.power_conduit.blockID == par1World.getBlockId(i, j, k))

{return true;}else{return false;}

}

public void checkSides()

{

par1World = this.worldObj;

i = this.xCoord;

j = this.yCoord;

k = this.zCoord;

side1 = checkBlockOnSide(i+1,j,k);

side2 = checkBlockOnSide(i-1,j,k);

side3 = checkBlockOnSide(i,j+1,k);

side4 = checkBlockOnSide(i,j-1,k);

side5 = checkBlockOnSide(i,j,k+1);

side6 = checkBlockOnSide(i,j,k-1);

}

 

public void updateEntity()

{

par1World = this.worldObj;

i = this.xCoord;

j = this.yCoord;

k = this.zCoord;

checkSides();

if(side1 == true){System.out.println("SIDE1");};

if(side2 == true){System.out.println("SIDE2");};

if(side3 == true){System.out.println("SIDE3");};

if(side4 == true){System.out.println("SIDE4");};

if(side5 == true){System.out.println("SIDE5");};

if(side6 == true){System.out.println("SIDE6");};

}

}

 

Yes, I can be mad :D

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

Hi again,

 

 

basicly you want your block to implement the "onNeighborBlockChange" method.

it is called everytime a neighbor block is updated.

Inside the implementations do

world.getBlockTileEntity

cast it into your "TileEntityPowerConduit" and call the updateEntity method you made

 

Cheers,

-hydroflame, FRev-

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Ou, I think a know what you mean... I think  :)

But how I can do this ? I dont know what you mean the world.getBlockTileEntity

 

 

And I have another question to you, I dont want to create new topic because I think it is not a big problem.

I created a custom block model for my machine. Everything is working fine, but the block is rotated only in one direction even If I try to place him to another direction.

Explanation: If I place the block, he isnt rotated as it need to be, If you know what I am want to say to you...

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

heuf .... here we go

 

 

 

 

//you class my block wtv thigny should be like this

public class someBlock extends Block{

//some code here like constructors n shit

public void onNeighborBlockChange(World world, int x, int y, int z, int neighborID) {

TileEntity tileEntity = world.getBlockTileEntity(x, y, z);//this will return the tile entity at this location

  if(tileEntity != null){//safety check

  if(tileEntity instanceof TileEntityYourBlock){//safety check

    TileEntityYourBlock tileEntityYourBlock = (TileEntityYourBlock) tileEntity;//cast into the right kind

    tileEntityYourBlock.updateEntity();//call the update function on the tile entity

  }

  }

 

}

//some more code about wtv

}

 

 

 

as for the other thing about orientation, search the forge wiki for "metadata"

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

SO :D

I created a rotation thingy.

Code in TileEntityPoweredMelterRender:

 

        @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.

                bindTextureByName(Mar21Extender.getRenderedTexture("powered_melter"));

        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                     

                GL11.glPushMatrix();

                GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

        //This rotation part is making the model rotated as well!

                if(MachinePoweredMelter.getSide == 0){GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);}

                if(MachinePoweredMelter.getSide == 1){GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F);}

                if(MachinePoweredMelter.getSide == 2){GL11.glRotatef(0.0F, 0.0F, 1.0F, 0.0F);}

                if(MachinePoweredMelter.getSide == 3){GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);}

        //A reference to your Model file. Again, very important.

                this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        //Tell it to stop rendering for both the PushMatrix's

                GL11.glPopMatrix();

                GL11.glPopMatrix();

        }

 

And changed code in Block class:

 

public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack)

    {

        int l = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

 

        if (l == 0)

        {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);

            this.getSide = l;

        }

 

        if (l == 1)

        {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);

            this.getSide = l;

        }

 

        if (l == 2)

        {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);

            this.getSide = l;

        }

 

        if (l == 3)

        {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);

            this.getSide = l;

        }

 

        if (par6ItemStack.hasDisplayName())

        {

            ((TileEntityPoweredMelter)par1World.getBlockTileEntity(par2, par3, par4)).func_94129_a(par6ItemStack.getDisplayName());

        }

    }

 

But there is ONE IMPORTANT PROBLEM :D

If I place the machine, it will rotate as I want... But every machine in world is rotated the same, If I place differently rotated machine, all machines gets the rotation of last placed machine!

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

as a opengl expert

//The PushMatrix tells the renderer to "start" doing something.

this is hilarious and also giving me cancer but dont worry I'm super anal about CG code

 

i know that its because of "MachinePoweredMelter.getSide" can you show me how this variable is set, it should be different for every block and it behing the same is the cause for the same orientation everywhere

 

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

yeah ok it makes a lot of sens.

 

getSide shouldnt be static, as static means its the same for everyone.

 

what you want is a way to access a world variable and call

world.getBlockMetadata(x, y, z);

thsi will return what "getSide" is, but the specific value for every different block, if you want more help,

 

 

 

put in spoiler every class you think could help, i dont have access to a minecraft build at the moment so i cant search by myself

 

 

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Yes ...

There is something with rotate in name :D :

 

        private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {

                int meta = world.getBlockMetadata(x, y, z);

                GL11.glPushMatrix();

                GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);

                GL11.glPopMatrix();

        }

 

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

yes, except if you have to render your block before you pull the matrix (ill spare you the details)

 

but technicly

 

pushMatrix
rotate
draw
popMatrix

 

bellow will not work

 

pushMatrix
rotate
popMatrix
draw

 

 

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Heh, I set! I am totaly render idiot :D

So, I have this in my rendering class:

 

package mar21.omega.machine.tileEntity.render;

 

import mar21.omega.machine.MachinePoweredMelter;

import mar21.omega.mar21.Mar21Extender;

import net.minecraft.block.Block;

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.world.World;

 

import org.lwjgl.opengl.GL11;

 

public class TileEntityPoweredMelterRender extends TileEntitySpecialRenderer {

       

        //The model of your block

        private final powered_melter model;

        private int getSide = MachinePoweredMelter.getSide;

       

        public TileEntityPoweredMelterRender() {

                this.model = new powered_melter();

        }

       

        private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {

                int meta = world.getBlockMetadata(x, y, z);

                GL11.glPushMatrix();

                GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);

                GL11.glPopMatrix();

        }

       

        @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.

                bindTextureByName(Mar21Extender.getRenderedTexture("powered_melter"));

        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                     

                GL11.glPushMatrix();

                GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

        //This rotation part is making the model rotated as well!

                if(getSide == 0){GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);}

                if(getSide == 1){GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F);}

                if(getSide == 2){GL11.glRotatef(0.0F, 0.0F, 1.0F, 0.0F);}

                if(getSide == 3){GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);}

        //A reference to your Model file. Again, very important.

                this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        //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) {

                Tessellator tess = Tessellator.instance;

                float brightness = block.getBlockBrightness(world, i, j, k);

                int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);

                int modulousModifier = skyLight % 65536;

                int divModifier = skyLight / 65536;

                tess.setColorOpaque_F(brightness, brightness, brightness);

                OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);

        }

}

 

What I need to write there :D ??

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

 

 

package mar21.omega.machine.tileEntity.render;

 

import mar21.omega.machine.MachinePoweredMelter;

import mar21.omega.mar21.Mar21Extender;

import net.minecraft.block.Block;

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.world.World;

 

import org.lwjgl.opengl.GL11;

 

public class TileEntityPoweredMelterRender extends TileEntitySpecialRenderer {

     

        //The model of your block

        private final powered_melter model;

     

        public TileEntityPoweredMelterRender() {

                this.model = new powered_melter();

        }

     

        //you dont need this function

        private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {

                int meta = world.getBlockMetadata(x, y, z);

                GL11.glPushMatrix();

                GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);

                GL11.glPopMatrix();

        }

     

        @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.

                bindTextureByName(Mar21Extender.getRenderedTexture("powered_melter"));

        //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                     

                GL11.glPushMatrix();

                GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

        //This rotation part is making the model rotated as well!

 

//i think you can do this

side = te.blockMetadata;

//and adjust the rotation after

 

                if(side == 0){GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);}

                if(side == 1){GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F);}

                if(side == 2){GL11.glRotatef(0.0F, 0.0F, 1.0F, 0.0F);}

                if(side == 3){GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);}

        //A reference to your Model file. Again, very important.

                this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        //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) {

                Tessellator tess = Tessellator.instance;

                float brightness = block.getBlockBrightness(world, i, j, k);

                int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);

                int modulousModifier = skyLight % 65536;

                int divModifier = skyLight / 65536;

                tess.setColorOpaque_F(brightness, brightness, brightness);

                OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);

        }

}

 

 

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Yes :D But this wont work, it says error nad this: change modifier of blockMetadata to static...

 

//EDIT

Small fixes and the code is working, but bit weird :D

It is not rotating properly, like before :!

 

//EDIT

Ok, So, I improved the rotating code and the rotating is working fine now.  :)

                int meta = te.getBlockMetadata();
                int rotation = 0;
                if(meta == 2){rotation = 180;}//SOUTH
                if(meta == 3){rotation = 0;}//NORTH
                if(meta == 4){rotation = -90;}//EAST
                if(meta == 5){rotation = 90;}//WEST
                GL11.glRotatef(rotation, 0, 1, 0);

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

:)

Ok, is there any way to show the model in the inventory? not the classic 16p image for the block?

Explanation:

It is showing the 16p image of block, not the custom rendered model ...

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

change modifier of blockMetadata to static

yeah sorry i didnt actually compiled the code, i tought you would understand what i meant

 

to render in inventory you have to make a class that implements IItemRenderer and render when the ItemRenderType is of INVENTORY_BLOCK

 

look at the javadoc and the actual class its pretty straightfoward

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

To show your model in your inventory, you need a item renderer.

 

Thats this class:

 

package YOUR_PACKAGE;

public class YOUR_ITEM_RENDERER implements IItemRenderer
{
    private YOUR_MODEL model;
    
    public YOUR_ITEM_RENDERER()
    {
        model = new YOUR_MODEL();
    }
    @Override
    public boolean handleRenderType(ItemStack itemstack, 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)
    {
        TileEntityRenderer.instance.renderTileEntityAt(new YOUR_TILEENTITY), 0.0D, 0.0D, 0.0D, 0.0F);
    }
}

 

 

And put this in your ClientProxy class:

 

MinecraftForgeClient.registerItemRenderer(YOUR_BLOCK_ID, new YOUR_ITEM_RENDERER());

 

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/

Link to comment
Share on other sites

Hey Man!

Heh, thanks for the item renderer, but :  :) I DONT HAVE PROXIES ! :)

So, this is only joke, I know how to do this without any proxies :)

Thanks, one more time !

 

//EDIT

So, there is one/two more questions:

 

1) In the randomDisplayTick() I have the particle generator like in normal furnace, it is possible to generate the particles in the block? because I want to have in this setup smoke and flame particles when machine is on:

XXXXX
XXYXX
XXXXX
XXXXX
FFFFFF

The Y character is point where I want to particles come from and

the F character is the front side of the block.

 

2)Is possible to set the texturemap for the custom render, to render 2 different texturemaps?

One map if the block is active and Second if the block is inactive

 

Thank for the IItemRenderer ! :)

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

To show your model in your inventory, you need a item renderer.

 

Thats this class:

 

package YOUR_PACKAGE;

public class YOUR_ITEM_RENDERER implements IItemRenderer
{
    private YOUR_MODEL model;
    
    public YOUR_ITEM_RENDERER()
    {
        model = new YOUR_MODEL();
    }
    @Override
    public boolean handleRenderType(ItemStack itemstack, 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)
    {
        TileEntityRenderer.instance.renderTileEntityAt(new YOUR_TILEENTITY), 0.0D, 0.0D, 0.0D, 0.0F);
    }
}

 

 

And put this in your ClientProxy class:

 

MinecraftForgeClient.registerItemRenderer(YOUR_BLOCK_ID, new YOUR_ITEM_RENDERER());

 

 

Really ?  :) This code is making game crash... Errorlog:

 

[iNFO] [sTDERR] java.lang.NullPointerException

[iNFO] [sTDERR] at net.minecraft.tileentity.TileEntity.getBlockType(TileEntity.java:222)

[iNFO] [sTDERR] at net.minecraft.tileentity.TileEntity.func_85027_a(TileEntity.java:281)

[iNFO] [sTDERR] at net.minecraft.client.renderer.tileentity.TileEntityRenderer.renderTileEntityAt(TileEntityRenderer.java:178)

[iNFO] [sTDERR] at mar21.omega.machine.tileEntity.render.TileEntityPoweredMelterInvRender.renderItem(TileEntityPoweredMelterInvRender.java:29)

[iNFO] [sTDERR] at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:167)

[iNFO] [sTDERR] at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:439)

[iNFO] [sTDERR] at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:858)

[iNFO] [sTDERR] at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:217)

[iNFO] [sTDERR] at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:158)

[iNFO] [sTDERR] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1000)

[iNFO] [sTDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:872)

[iNFO] [sTDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:761)

[iNFO] [sTDERR] at java.lang.Thread.run(Unknown Source)

 

 

TileEntityPoweredMelterInvRender:

 

package mar21.omega.machine.tileEntity.render;

 

import mar21.omega.machine.tileEntity.TileEntityPoweredMelter;

import net.minecraft.client.renderer.tileentity.TileEntityRenderer;

import net.minecraft.item.ItemStack;

import net.minecraftforge.client.IItemRenderer;

 

public class TileEntityPoweredMelterInvRender implements IItemRenderer

{

    private powered_melter_model model;

   

    public TileEntityPoweredMelterInvRender()

    {

        model = new powered_melter_model();

    }

    @Override

    public boolean handleRenderType(ItemStack itemstack, 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)

    {

        TileEntityRenderer.instance.renderTileEntityAt(new TileEntityPoweredMelter(), 0.0D, 0.0D, 0.0D, 0.0F);

    }

}

 

 

My registering line in base mod class:

 

MinecraftForgeClient.registerItemRenderer(powered_melter_idle.blockID, new TileEntityPoweredMelterInvRender());

 

 

I dont know why, eclipse doesnt show any errors..

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

MinecraftForgeClient.registerItemRenderer(powered_melter_idle.blockID, new TileEntityPoweredMelterInvRender());

thsi should be in a client proxy, not in a base mod class

 

 

2 eclipse isnt some kind of magical god, it will only show compilation errors, not runtime errors

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

-hydroflame, author of the forge revolution-

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • rp.crazyheal.xyz mods  
    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
  • Topics

×
×
  • Create New...

Important Information

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