Jump to content

Issues with getting data from a tile entity to use in a GUI [Solved]


Recommended Posts

Posted

I've run into a small issue with a mod I'm trying to make. I attempted to make a special furnace, so I ended up copying the normal MC furnace so I could edit that code, and made a custom GUI for it. However, there was an issue in all this. Whenever I try to get the time the special furnace has been burning, I keep getting a 0 out of it. The furnace does work as intended, it does burn wood into coal etc. But for some reason the furnace does not give me the expected number when I try to get the number of ticks it has been burning.

 

I did debug things, and the burn timer IS something different from 0, yet the function keep returning 0. I really don't know what I can do about that :/ I suspect that it might have something to do with client/server not communicating properly? When I did debug the code, the value I was interested in reading wasn't zero when debugging the entity update function, but when debugging the GUI code, the value of "furnaceBurnTime" was zero the whole time.

 

The result of the function returning 0 is that I'm unable to display visually how long the item in the furnace has been burning, and I assume I won't be able to display the temperature (Which I'll add later) of the item either with this issue.

 

If the solution is so simple that you feel like facepalming, please note that this is my first time I attempt to make a container, GUI and tile entity. In fact, it's my first time trying to make a real mod, I'm very new to the whole modding this ^^

Any help would be much appreciated!

 

Code pieces that might be of interest:

GuiSugarsmelter:

[hide]

@SideOnly(Side.CLIENT)
public class GuiSugarsmelter extends GuiContainer
{

TileEntitySugarsmelter smelter;

public GuiSugarsmelter (InventoryPlayer inventoryPlayer, TileEntitySugarsmelter tileEntity)
{
	//the container is instanciated and passed to the superclass for handling
	super(new ContainerSugarsmelter(inventoryPlayer, tileEntity));
	smelter = tileEntity;
}

@Override
protected void drawGuiContainerForegroundLayer()
{
	//draw text and stuff here
	//the parameters for drawString are: string, x, y, color
	fontRenderer.drawString("Sugar smelter", 8, 6, 4210752);
	//draws "Inventory" or your regional equivalent
	fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752);
}

@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
	//draw your Gui here, only thing you need to change is the path
	int texture = mc.renderEngine.getTexture("/hepolite/candy/guisugarsmelter.png");
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.renderEngine.bindTexture(texture);
	int x = (width - xSize) / 2;
	int y = (height - ySize) / 2;
	this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);

	int time;

	if (smelter.isBurning())
	{
	    time = smelter.getBurnTimeRemainingScaled(12);
	    this.drawTexturedModalRect(x+56, y+36 + 12-time, 176, 12-time, 14, time+2);
	}

	time = smelter.getCookProgressScaled(24);
	drawTexturedModalRect(time+x+79, y+34, 176, 14, time+1, 16);
}

}

[/hide]

 

ContainerSugarsmelter:

[hide]

public class ContainerSugarsmelter extends Container
{

    protected TileEntitySugarsmelter tileEntity;
   
    public ContainerSugarsmelter(InventoryPlayer inventoryPlayer, TileEntitySugarsmelter te)
    {
        tileEntity = te;

        //the Slot constructor takes the IInventory and the slot number in that it binds to
        //and the x-y coordinates it resides on-screen
        //addSlotToContainer(new Slot(tileEntity, 0, 76, 37));
        this.addSlotToContainer(new Slot(te, 0, 56, 17));
        this.addSlotToContainer(new Slot(te, 1, 56, 53));
        this.addSlotToContainer(new SlotFurnace(inventoryPlayer.player, te, 2, 116, 35));
        
        //commonly used vanilla code that adds the player's inventory
        bindPlayerInventory(inventoryPlayer);
    }
    
    @Override
    public boolean canInteractWith(EntityPlayer player)
    {
        return tileEntity.isUseableByPlayer(player);
    }
    
    protected void bindPlayerInventory(InventoryPlayer inventoryPlayer)
    {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
                                8 + j * 18, 84 + i * 18));
            }
        }

        for (int i = 0; i < 9; i++)
        {
            addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
        }
    }
    
    @Override
    public ItemStack transferStackInSlot(int slot)
    {
    ItemStack stack = null;
    Slot slotObject = (Slot) inventorySlots.get(slot);

    //null checks and checks if the item can be stacked (maxStackSize > 1)
    if (slotObject != null && slotObject.getHasStack())
    {
        ItemStack stackInSlot = slotObject.getStack();
        stack = stackInSlot.copy();

        //merges the item into player inventory since its in the tileEntity
        if (slot == 0)
        {
            if (!mergeItemStack(stackInSlot, 1, inventorySlots.size(), true))
            {
                return null;
            }
        //places it into the tileEntity is possible since its in the player inventory
        }
        else if (!mergeItemStack(stackInSlot, 0, 1, false))
        {
            return null;
        }

        if (stackInSlot.stackSize == 0)
        {
            slotObject.putStack(null);
        }
        else
        {
            slotObject.onSlotChanged();
        }
    }

    return stack;
}
}

[/hide]

 

TileEntitySugarsmelter:

[hide]

	@SideOnly(Side.CLIENT)
public int getCookProgressScaled(int par1)
{
    return this.furnaceCookTime * par1 / this.cookTime;
}

@SideOnly(Side.CLIENT)
public int getBurnTimeRemainingScaled(int par1)
{
    if (this.currentItemBurnTime == 0)
    {
        this.currentItemBurnTime = this.cookTime;
    }

    return this.furnaceBurnTime * par1 / this.currentItemBurnTime;
}

public boolean isBurning()
{
    return this.furnaceBurnTime > 0;
}

[/hide]

 

getClientGuiElement:

[hide]

public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
    {
        TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
        if(tileEntity instanceof TileEntitySugarsmelter)
        {
            return new GuiSugarsmelter(player.inventory, (TileEntitySugarsmelter)tileEntity);
        }
        return null;
    }

[/hide]

 

Posted

Ah, thanks a lot! I got it to work. However, there's only one more thing I'm wondering about...

 

Right now I'm sending a packet in the onBlockActivated under BlockSugarsmelter, which is probably a terrible place to send this packet, as the values don't change while the GUI is open, only when opening the GUI. Where should I send this packet, so that it sends only when the GUI is open?

Posted

in the TileEntity public void updateEntity() is where i send my packets but there are a few other place like getAuxPacket(). I suggest if you use updateEntity() to code it like this

int count = 0;
public void updateEntity()
{
if(count++ > 10)
{
count = 0;
if(!worldObj.isRemote)
{
//TODO send packet
}
}

this will only send the packet on the server and reduce lag to only send a packet 2 times a second.

Posted

I was afraid I had to use the updateEntity function, but oh well... Didn't think of adding a delay though, and with that it would definitely work well. Added some code, and it works perfectly, thanks again!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Looks like an issue with biomeswevegone
    • In the server.properties, set max-tick-time to -1   if there are further issues, make a test without distanthorizons
    • Verified user can get a $300 off TℰℳU Coupon code using the code ((“{{ '[''com31844'']}}”)). This TℰℳU $100Off code is specifically for new and existing customers both and can be redeemed to receive a $100discount on your purchase. Our exclusive TℰℳU Coupon code offers a flat $100off your purchase, plus an additional 100% discount on top of that. You can slash prices by up to $100as a new TℰℳU customer using code ((“{{ '[''com31844'']}}”)). Existing users can enjoy $100off their next haul with this code. But that’s not all! With our TℰℳU Coupon codes for 2025, you can get up to 90% discount on select items and clearance sales. Whether you’re a new customer or an existing shopper, our TℰℳU codes provide extra discounts tailored just for you. Save up to 100% with these current TℰℳU Coupons ["^"{{ '[''com31844'']}} "^"] for April 2025. The latest TℰℳU coupon codes at here. New users at TℰℳU receive a $100discount on orders over $100Use the code ((“{{ '[''com31844'']}}”)) during checkout to get TℰℳU Coupon $100Off For New Users. You can save $100Off your first order with the coupon code available for a limited time only. TℰℳU 90% Off promo code ((“{{ '[''com31844'']}}”)) will save you $100on your order. To get a discount, click on the item to purchase and enter the coe. Yes, offers $100Off coupon code “{{ '[''com31844'']}}” for first time users. You can get a $100bonus plus $100Off any purchase at TℰℳU with the $100Coupon Bundle at TℰℳU if you sign up with the referral code ((“{{ '[''com31844'']}}”)) and make a first purchase of $100or more. Free TℰℳU codes $100off — ((“{{ '[''com31844'']}}”)) Get a $100discount on your TℰℳU order with the promo code "{{ '[''com31844'']}}". You can get a discount by clicking on the item to purchase and entering this TℰℳU Coupon code $100off ((“{{ '[''com31844'']}}”)). ŢℰNew User Coupon ((“{{ '[''com31844'']}})): Up To $100OFF For First-Time Users Our TℰℳU first-time user coupon codes are designed just for new customers, offering the biggest discounts and the best deals currently available on TℰℳU To maximize your savings, download the TℰℳU app and apply our TℰℳU new user coupon during checkout. TℰℳU Coupon Codes For Existing Users ((“{{ '[''com31844'']}}”)): $100Price Slash Have you been shopping on TℰℳU or a while? Our TℰℳU Coupon for existing customers is here to reward you for your continued support, offering incredible discounts on your favorite products. TℰℳU Coupon For $100Off ((“{{ '[''com31844'']}}”)): Get A Flat $100Discount On Order Value Get ready to save big with our incredible TℰℳU Coupon for $100off! Our amazing ŢℰM$100off coupon code will give you a flat $100discount on your order value, making your shopping experience even more rewarding. TℰℳU Coupon Code For $100Off ((“{{ '[''com31844'']}}”)): For Both New And Existing Customers Our incredible TℰℳU Coupon code for $100off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our $100off code for TℰℳU will give you an additional discount! TℰℳU Coupon Bundle ((“{{ '[''com31844'']}}”)): Flat $100Off + Up To $100Discount Get ready for an unbelievable deal with our TℰℳU Coupon bundle for 2025! Our TℰℳU Coupon bundles will give you a flat $100discount and an additional $100off on top of it. Free TℰℳU Coupons ((“{{ '[''com31844'']}}”)): Unlock Unlimited Savings! Get ready to unlock a world of savings with our free TℰℳU Coupons! We’ve got you covered with a wide range of TℰℳU Coupon code options that will help you maximize your shopping experience. 100% Off TℰℳU Coupons, Promo Codes + 25% Cash Back ((“{{ '[''com31844'']}}”)) Redeem TℰℳU Coupon Code ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FOR EXISTING CUSTOMERS ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FIRST ORDER ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF REDDIT ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FOR EXISTING CUSTOMERS REDDIT ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF CODE ((“{{ '[''com31844'']}}”)) TℰℳU 70 OFF COUPON 2025 ((“{{ '[''com31844'']}}”)) DOMINOS 70 RS OFF COUPON CODE ((“{{ '[''com31844'']}}”)) WHAT IS A COUPON RATE ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FOR EXISTING CUSTOMERS ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FIRST ORDER ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FREE SHIPPING ((“{{ '[''com31844'']}}”)) You can get an exclusive $100off discount on your TℰℳU purchase with the code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}].This code is specially designed for new customers and offers a significant price cut on your shopping. Make your first purchase on TℰℳU more rewarding by using this code to get $100off instantly.   TℰℳU Coupon Code For $100Off [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]: Get A Flat $100Discount On Order Value Get ready to save big with our incredible TℰℳU coupon for $100off! Our coupon code will give you a flat $100discount on your order value, making your shopping experience even more rewarding.   Exclusive TℰℳU Discount Code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]: Flat $300 OFF for New and Existing Customers Using our TℰℳU promo code you can get A$ 200 off your order and 100% off using our TℰℳU promo code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]. As a new TℰℳU customer, you can save up to $100using this promo code. For returning users, our TℰℳU promo code offers a $100price slash on your next shopping spree. This is our way of saying thank you for shopping with us! Get ready to save big with our incredible TℰℳU Coupon code for $300 off! Our amazing TℰℳU $300 off coupon code will give you a flat $300 discount on your order value, making your shopping experience even more rewarding.   TℰℳU Coupon Code For 40% Off ["{com31844}"] For Both New And Existing Customers   Our incredible TℰℳU Coupon code for 40% off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our 40% off code for TℰℳU will give you an additional discount!   TℰℳU Coupon Bundle ["{com31844}"]: Flat $300 Off + Up To 90% Discount   Get ready for an unbelievable deal with our TℰℳU Coupon bundle for 2025! Our TℰℳU Coupon bundles will give you a flat $300 discount and an additional 40% off on top of it.   Free TℰℳU Coupons ["{com31844}"]: Unlock Unlimited Savings!   Get ready to unlock a world of savings with our free TℰℳU Coupons! We’ve got you covered with a wide range of TℰℳU Coupon code options that will help you maximize your shopping experience.   50% Off TℰℳU Coupons, Promo Codes + 25% Cash Back ["{com31844}"]   Redeem TℰℳU Coupon Code ["{com31844}"]   TℰℳU Coupon $300 OFF ["{com31844}"]   TℰℳU Coupon $300 OFF ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS ["{com31844}"]   TℰℳU Coupon $300 OFF FIRST ORDER ["{com31844}"]   TℰℳU Coupon $300 OFF FIRST ORDER ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS FREE SHIPPING USA ["{com31844}"]   TℰℳU Coupon $300 OFF HOW DOES IT WORK ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS CANADA ["{com31844}"]   TℰℳU Coupon $300 OFF 2025 ["{com31844}"]   TℰℳU Coupon $300 OFF FOR NEW CUSTOMERS ["{com31844}"]   TℰℳU Coupon $300 OFF CANADA ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS FIRST ORDER ["{com31844}"]   TℰℳU 300 OFF COUPON BUNDLE ["{com31844}"]   This TℰℳU coupon $300 off is designed to provide substantial savings on your purchases, making shopping for your favorite items easier than ever. With our $300 off TℰℳU coupon, you'll be amazed at how much you can save on your next order. Here are the key benefits you can expect when using our coupon code {com31844} "OR" {com31844}: {com31844} "OR" {com31844}: Flat $300 off on your purchase {com31844} "OR" {com31844}: $300 coupon pack for multiple uses {com31844} "OR" {com31844}: $300 flat discount for new customers {com31844} "OR" {com31844}: Extra $300 promo code for existing customers {com31844} "OR" {com31844}: $300 coupon exclusively for USA/Canada users H2: TℰℳU Coupon Code $300 Off For New Users In 2024 New users can reap the highest benefits by using our coupon code on the TℰℳU app. This TℰℳU coupon $300 off is specifically designed to welcome new customers with incredible savings  
    • Now the serve runs for a bit, then crashes after 20 minutes of running, what's the issue here? apologies if I need to start a new post and didn't https://pastebin.com/uBpp5bCz  
  • Topics

×
×
  • Create New...

Important Information

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