Jump to content

Recommended Posts

Posted

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

Posted

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);
    }

Posted

Then what's the other packet for?

The packet is for syncing the server to client, so that energy would display correctly, and since im only adding cookTime and totalCookTime to getField and setField, so im not calling upon it in the gui yet directly calling upon the energy stored and max stored

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.