Jump to content

Recommended Posts

Posted

Hey guys, so im working on a furnace sort of block and an having trouble rendering the progress bar, it runs with the same ticks for each item/block as a furnace, so i thought id take a look, and tried doing what the furnace did to see if it would work but even then i cant get it to work, what iv tried

public class GuiTestFurnace extends GuiContainer {

public static final ResourceLocation TestFurnace = new ResourceLocation(Info.MODID, "textures/gui/test_furnace.png");
    public static final int WIDTH = 176;
    public static final int HEIGHT = 166;
    TileTestFurnace testFurnace;

    public GuiPulverizer(TileTestFurnace tileEntity, TestFurnaceContainer container, TileEntity te) {
        super(container);
        xSize = WIDTH;
        ySize = HEIGHT;
        testFurnace= (TileTestFurnace ) tileEntity;
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        mc.getTextureManager().bindTexture(TestFurnace );
        drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

        int l = this.getCookProgressScaled(24);
        this.drawTexturedModalRect(guiLeft + 81, guiTop + 27, 176, 46, l + 1, 16);
    }

    private int getCookProgressScaled(int pixels)
    {
        int i = this.testFurnace.getField(0);
        int j = this.testFurnace.getField(1);
        return j != 0 && i != 0 ? i * pixels / j : 0;
    }
}

 

and my getField in my testFurnace is

public int getField(int id)
{
	switch (id)
	{
		case 0:
			return this.cookTime;
		case 1:
			return this.totalCookTime;
		default:
			return 0;
	}
}

public void setField(int id, int value)
{
	switch (id)
	{
		case 0:
			this.cookTime = value;
			break;
		case 1:
			this.totalCookTime = value;
	}
}

Posted

Are your cookTime and totalCookTime values synced to the client?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Hi abused_master,

I don't know if that's your issue, however, when I used the furnace code in GUI, It did not work for me also.

So, I changed my getScaled class to something like this.

private int getCookProgressScaled(int pixels) {
    return (this.testFurnace.getField(0) * pixels / this.testFurnace.getField(1));
}

I always use this piece of code for my progress bars, It works like a charm.

 

Edit: make sure you typed the right values in drawGuiContainerBackgroundLayer.

 

See if it works,

Alanzote.

Posted

Are your cookTime and totalCookTime values synced to the client?

yeah they are

 

Hi abused_master,

I don't know if that's your issue, however, when I used the furnace code in GUI, It did not work for me also.

So, I changed my getScaled class to something like this.

private int getCookProgressScaled(int pixels) {
    return (this.testFurnace.getField(0) * pixels / this.testFurnace.getField(1));
}

I always use this piece of code for my progress bars, It works like a charm.

 

Edit: make sure you typed the right values in drawGuiContainerBackgroundLayer.

 

See if it works,

Alanzote.

yeah i did type the right values i tested with it, i also tried the code u gave but that didnt solve it either

Posted
@Override
public void update() {
	if(!getWorld().isRemote) {
		PacketHandler.INSTANCE.sendToAll(new MessageTEUpdate(this));
	}

	boolean flag1 = false;

	if (!this.worldObj.isRemote)
	{
		ItemStack itemstack = (ItemStack)this.testFurnaceInv.get(1);

		if (storage.getEnergyStored() > 50 || !itemstack.func_190926_b() && !((ItemStack)this.testFurnaceInv.get(0)).func_190926_b())
		{
			if (!(storage.getEnergyStored() > 50) && this.canSmelt())
			{
				if (storage.getEnergyStored() > 50)
				{
					flag1 = true;

					if (!itemstack.func_190926_b())
					{
						Item item = itemstack.getItem();
						itemstack.func_190918_g(1);

						if (itemstack.func_190926_b())
						{
							ItemStack item1 = item.getContainerItem(itemstack);
							this.testFurnaceInv.set(1, item1);
						}
					}
				}
			}

			if (storage.getEnergyStored() > 50 && this.canSmelt())
			{
				++this.cookTime;

				if (this.cookTime == this.totalCookTime)
				{
					this.cookTime = 0;
					this.totalCookTime = this.getCookTime((ItemStack)this.testFurnaceInv.get(0));
					this.SmeltItem();
					flag1 = true;
				}
			}
			else
			{
				this.cookTime = 0;
			}
		}
		else if (!(storage.getEnergyStored() > 50) && this.cookTime > 0)
		{
			this.cookTime = MathHelper.clamp_int(this.cookTime - 2, 0, this.totalCookTime);
		}
	}

	if (flag1)
	{
		this.markDirty();
	}

}

public void SmeltItem() {
	if (this.canPulverize()) {
		ItemStack itemstack = (ItemStack) this.testFurnaceInv.get(0);
		ItemStack itemstack1 = RecipeTestFurnace.instance().getSmeltingResult(itemstack);
		ItemStack itemstack2 = (ItemStack) this.testFurnaceInv.get(1);
		if (storage.getEnergyStored() >= 50 && !itemstack1.func_190926_b()) {
			storage.setEnergyStored(storage.getEnergyStored() - 50);

			if (itemstack2.func_190926_b()) {
				this.testFurnaceInv.set(1, itemstack1.copy());
			} else if (itemstack2.getItem() == itemstack1.getItem()) {
				itemstack2.func_190917_f(itemstack1.func_190916_E());
			}
			itemstack.func_190918_g(1);
		}
	}
}

Posted

One of this conditions must be returning false, I recomend debugging with System.out.prinln("String");

if (storage.getEnergyStored() > 50 || !itemstack.func_190926_b() && !((ItemStack)this.testFurnaceInv.get(0)).func_190926_b())

if (storage.getEnergyStored() > 50 && this.canSmelt())

Posted

I had the same problem, and I fixed it by changing drawContainerForeGroundLayer to drawContianerForegroundLayer. I see that is not the problem you have, though.

 

And that is why you should use @Override, to catch mistakes like that.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

So i found out *derp* that i had to sync the values with my Container aswell, so i did that

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.tileTestFurnace.getField(0))
            {
                icontainerlistener.sendProgressBarUpdate(this, 2, this.tileTestFurnace.getField(0));
            }

            if (this.totalCookTime != this.tileTestFurnace.getField(1))
            {
                icontainerlistener.sendProgressBarUpdate(this, 3, this.tileTestFurnace.getField(1));
            }
        }

        this.cookTime = this.tileTestFurnace.getField(0);
        this.totalCookTime = this.tileTestFurnace.getField(1);
    }


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

is this the correct?

Posted

So i found out *derp* that i had to sync the values with my Container aswell, so i did that

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.tileTestFurnace.getField(0))
            {
                icontainerlistener.sendProgressBarUpdate(this, 2, this.tileTestFurnace.getField(0));
            }

            if (this.totalCookTime != this.tileTestFurnace.getField(1))
            {
                icontainerlistener.sendProgressBarUpdate(this, 3, this.tileTestFurnace.getField(1));
            }
        }

        this.cookTime = this.tileTestFurnace.getField(0);
        this.totalCookTime = this.tileTestFurnace.getField(1);
    }


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

is this the correct?

Does it work? If not I suggest changing

icontainerlistener.sendProgressBarUpdate(this, 2, this.tileTestFurnace.getField(0));
// To this
icontainerlistener.sendProgressBarUpdate(this, 0, this.tileTestFurnace.getField(0));
// Or this
icontainerlistener.sendProgressBarUpdate(this, 2, this.tileTestFurnace.getField(2));

Do you see the difference?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

yeah i found the mistake after i posted, now what ends up happening is the progress bar flickers on sometimes the progress when working but doesnt stay on the entire time it works, example:

https://gyazo.com/a5b6a3b85575992e7e9a49b2b23db499

How fast is the process?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

sure:

for the 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.tileTestFurnace.getField(0))
            {
                icontainerlistener.sendProgressBarUpdate(this, 0, this.tileTestFurnace.getField(0));
            }

            if (this.totalCookTime != this.tileTestFurnace.getField(1))
            {
                icontainerlistener.sendProgressBarUpdate(this, 1, this.tileTestFurnace.getField(1));
            }
        }

        this.cookTime = this.tileTestFurnace.getField(0);
        this.totalCookTime = this.tileTestFurnace.getField(1);
    }

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

 

Gui:

//in the drawGuiContainerBackgroundLayer
int l = this.getCookProgressScaled(24);
        this.drawTexturedModalRect(guiLeft + 81, guiTop + 27, 176, 46, l + 1, 16);

    private int getCookProgressScaled(int pixels)
    {
        int i = this.tileTestFurnace.getField(0);
        int j = this.tileTestFurnace.getField(1);
        return j != 0 && i != 0 ? i * pixels / j : 0;
    }

 

and the getField and setField:

@Override
public int getField(int id)
{
	switch (id)
	{
		case 0:
			return this.cookTime;
		case 1:
			return this.totalCookTime;
		default:
			return 0;
	}
}

@Override
public void setField(int id, int value)
{
	switch (id)
	{
		case 0:
			this.cookTime = value;
			break;
		case 1:
			this.totalCookTime = value;
	}
}

@Override
public int getFieldCount() {
	return 4;
}

Posted

Use printlns or the debugger to check:

- Is

getCookProgressScaled

returning the expected values?

- Is your TE's

getField

returning the expected values?

- Is your TE fully synced between client and server?

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.