Jump to content

[1.11] TileEntity Update


abused_master

Recommended Posts

Hey guys, so i'm having some issues with my TileEntity updating.

So with my TE i'm rending a power bar and a progress bar, as its a crusher. I have a packet that updates my TE. The problem is when i call upon that packet, the power bar renders just fine but the progress bar doesn't render. But on removing it the progress bar is fine but power isn't.

Packet:

public class MessageTEUpdate implements IMessage {
    public NBTTagCompound tag = new NBTTagCompound();

    public MessageTEUpdate(){
    }

    public MessageTEUpdate(TileEntity tile){
        this.tag = tile.getUpdateTag();
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        tag = ByteBufUtils.readTag(buf);
    }

    @Override
    public void toBytes(ByteBuf buf) {
        ByteBufUtils.writeTag(buf, tag);
    }

    public static class MessageHolder implements IMessageHandler<MessageTEUpdate,IMessage>
    {
        @SideOnly(Side.CLIENT)
        @Override
        public IMessage onMessage(final MessageTEUpdate message, final MessageContext ctx) {

            Minecraft.getMinecraft().addScheduledTask(()-> {
                if ((Minecraft.getMinecraft().thePlayer.getEntityWorld()).getTileEntity(new BlockPos(message.tag.getInteger("x"),message.tag.getInteger("y"),message.tag.getInteger("z"))) != null){
                    Minecraft.getMinecraft().thePlayer.getEntityWorld().getTileEntity(new BlockPos(message.tag.getInteger("x"),message.tag.getInteger("y"),message.tag.getInteger("z"))).readFromNBT(message.tag);
                    Minecraft.getMinecraft().thePlayer.getEntityWorld().getTileEntity(new BlockPos(message.tag.getInteger("x"),message.tag.getInteger("y"),message.tag.getInteger("z"))).markDirty();
                }
            });
            return null;
        }
    }
}

 

Progress bar & Power Bar

    private int getEnergyScaled(int i)
    {
        return crusher.storage.getEnergyStored() * i / crusher.storage.getMaxEnergyStored();

    }

public void renderEnergy() {
            int i = getEnergyScaled(40);
            this.drawTexturedModalRect(guiLeft + 10, guiTop + 9, 178, 4, 12, i);
    }

    public void renderProgress() {
        int l = this.getCookProgressScaled(24);
        this.drawTexturedModalRect(guiLeft + 81, guiTop + 26, 176, 46, l, 16);
    }

 

and then i'm calling those in my drawGuiContainerBackgroundLayer

any help in fixing this is appreciated

Link to comment
Share on other sites

I was doing this in my container

    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for (int i = 0; i < this.listeners.size(); ++i)
        {
            IContainerListener icontainerlistener = (IContainerListener)this.listeners.get(i);

            if (this.cookTime != this.tileCrusher.getField(1))
            {
                icontainerlistener.sendProgressBarUpdate(this, 1, this.tileCrusher.getField(1));
            }

            if (this.totalCookTime != this.tileCrusher.getField(2))
            {
                icontainerlistener.sendProgressBarUpdate(this, 2, this.tileCrusher.getField(2));
            }
        }

        this.cookTime = this.tileCrusher.getField(1);
        this.totalCookTime = this.tileCrusher.getField(2);
    }

    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int id, int data)
    {
        this.tileCrusher.setField(id, data);
    }

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.



×
×
  • Create New...

Important Information

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