Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

  • Author

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

  • Author

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.