Jump to content

[1.8] Rendering Tile Entities


AnZaNaMa

Recommended Posts

I've been working on my mod for minecraft 1.8 and so far, everything has been going fine, but I just can't seem to figure out why my tileentity will not render. I have a blockstate json file for it, a json in models under item AND block, the texture is in the correct place, but for some reason the block will not render in the world.

 

It does render as an item, but as soon as it is placed, I just get a completely transparent texture. I have tried using a custom TESR and that is not working either, please help me figure this out.

 

Block class:

public class Energizer extends BlockContainer {
    public Energizer(Material material, String unlocalizedName, float localhardness, float localresistance){
        super(material);
        GameRegistry.registerBlock(this, unlocalizedName);
        setCreativeTab(ExpTools.creativeTab);
        setHardness(localhardness);
        setResistance(localresistance);
        setUnlocalizedName(unlocalizedName);
    }

    public TileEntity createNewTileEntity(World world, int number){
        return new TileEntityEnergizer();
    }

    @Override
    public void onBlockClicked(World world, BlockPos position, EntityPlayer player){
        TileEntity entity = world.getTileEntity(position);
        if(entity instanceof TileEntityEnergizer) {
            player.addChatMessage(new ChatComponentText("Energy Stored: " + ((TileEntityEnergizer)world.getTileEntity(position)).getEnergyContained()));
        }
    }

    @Override
    public boolean isOpaqueCube(){
        return true;
    }
}

 

TileEntity Class:

public class TileEntityEnergizer extends TileEntity implements IUpdatePlayerListBox {

    private static int energyContained;
    private static BlockPos position;
    private static byte repetitions;

    public TileEntityEnergizer(){
        super();
        this.energyContained = 0;
        this.position = BlockPos.ORIGIN;
        this.repetitions = 0;
    }

    @Override
    public void update(){
        if(!this.worldObj.isRemote)
        this.repetitions++;
        if(this.repetitions >= 20){
            this.repetitions = 0;
            LogHelper.info("Looking for Entities from position (" + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + ") to (" + pos.getX() + ", " + (pos.getY()+1) + ", " + pos.getZ() + ")");
            List entities = this.worldObj.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), new BlockPos(pos.getX() + 1, pos.getY() + 2, pos.getZ() + 1)), IEntitySelector.selectAnything);
            LogHelper.info("Found Entities:");
            for(int i=0; i < entities.size(); i++){
                LogHelper.info(entities.get(i).toString());
            }
            for(int i=0; i < entities.size(); i++){
                if(entities.get(i) instanceof EntityItem){
                    LogHelper.info("Entity is EntityItem");
                    ItemStack items = new ItemStack(((EntityItem) entities.get(i)).getEntityItem().getItem(), ((EntityItem) entities.get(i)).getEntityItem().stackSize, ((EntityItem) entities.get(i)).getEntityItem().getMetadata());
                    LogHelper.info("ItemStack UnlocalizedName: " + items.getItem().getUnlocalizedName());
                    int energyToMachine = Energy.getItemEnergyValue(items.getItem());
                    LogHelper.info("ItemStack Energy Value found to be: " + energyToMachine);
                    ((EntityItem) entities.get(i)).setInfinitePickupDelay();
                    this.energyContained += (energyToMachine * ((EntityItem) entities.get(i)).getEntityItem().stackSize);
                    ((EntityItem) entities.get(i)).getEntityItem().stackSize = 0;
                    LogHelper.info("Item Removed");
                }
                else if(entities.get(i) instanceof EntityPlayer){
                    Energy.tryMoveEnergy(this, (EntityPlayer)entities.get(i), 100);
                }
            }
        }
    }

    @Override
    public void readFromNBT(NBTTagCompound compound){
        this.energyContained = compound.getInteger("Energy");
    }

    @Override
    public void writeToNBT(NBTTagCompound compound){
        compound.setInteger("Energy", this.energyContained);
    }

    public int getEnergyContained(){
        return this.energyContained;
    }

    public void setEnergyContained(int amount){
        this.energyContained = amount;
    }

    public void addEnergyContained(int amount){
        this.energyContained += amount;
    }

    public void subtractEnergyContained(int amount){
        this.energyContained -= amount;
    }
}

 

Tile Entity Special Renderer Class:

public class EnergyToolsTESR extends TileEntitySpecialRenderer{
    public EnergyToolsTESR(){

    }

    @Override
    public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f, int number){
        ResourceLocation image = new ResourceLocation(Reference.MODID + ":textures/blocks/energizer.png");
        this.bindTexture(image);
        Tessellator tessellator = Tessellator.getInstance();
        GL11.glPushMatrix();
        GL11.glTranslated(x, y + 1, z);
        tessellator.getWorldRenderer().addVertexWithUV(0, 0, 0, 0, 0);
        tessellator.getWorldRenderer().addVertexWithUV(0, 1, 0, 0, 1);
        tessellator.getWorldRenderer().addVertexWithUV(1, 1, 0, 1, 1);
        tessellator.getWorldRenderer().addVertexWithUV(1, 0, 0, 1, 0);

        tessellator.getWorldRenderer().addVertexWithUV(0, 0, 0, 0, 0);
        tessellator.getWorldRenderer().addVertexWithUV(1, 0, 0, 1, 0);
        tessellator.getWorldRenderer().addVertexWithUV(1, 1, 0, 1, 1);
        tessellator.getWorldRenderer().addVertexWithUV(0, 1, 0, 0, 1);
        tessellator.getWorldRenderer().startDrawingQuads();
        tessellator.draw();
        GL11.glPopMatrix();
    }
}

 

I have registered the block icon and bound the TESR in the init() method of my ClientProxy.

- Just because things are the way they are doesn't mean they can't be the way you want them to be. Unless they're aspen trees. You can tell they're aspens 'cause the way they are.

Link to comment
Share on other sites

You have to call

WorldRenderer#startDrawingQuads()

before you add the vertices, and

WorldRenderer#draw()

after you add the vertices.

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

Thanks for your help. I haven't really been able to find any good tutorials for OpenGL. Anyone know a good one?

 

Also, if you have it, I would love a good directx tutorial, though that's not related to this question at all :P

- Just because things are the way they are doesn't mean they can't be the way you want them to be. Unless they're aspen trees. You can tell they're aspens 'cause the way they are.

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.