Jump to content

[1.11] Rendering Progress Bar


abused_master

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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())

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

The exact same as a vanilla furnace, if u mean the flickering, its always random

Could you post the updated rendering code?

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.

Link to comment
Share on other sites

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

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a keybind where you spit like a llama. On singleplayer both the entity and particle spawn and it's sound is played (https://youtu.be/bpxnFDuWw_I). But on a server only the entity is spawned and nothing else (https://youtu.be/veVQ4zSqnIA), no particles nor sound. Upon starting the server I have noticed this error in the window (https://postimg.cc/K3KDCpMY), don't know if it's relevant. The server works fine but when I want to spit the following pops up in the serverlog '''Attempted to load class net/minecraft/client/player/LocalPlayer for invalid dist DEDICATED_SERVER''' (https://postimg.cc/LqTDP1Sm). I have prepared the following code of the Server-to-Client packet class which I have made to spawn mentioned particles and sounds. package mett.palemannie.tabakmod.networking.packets; import net.minecraft.client.Minecraft; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.sounds.SoundEvents; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class SpuckEffektS2CPacket { public SpuckEffektS2CPacket(){ } public SpuckEffektS2CPacket(FriendlyByteBuf buf){ } public void toBytes(FriendlyByteBuf buf){ } public boolean handle(Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context context = supplier.get(); context.enqueueWork(()-> { Player player = Minecraft.getInstance().player; //Attempted to load class net/minecraft/client/player/LocalPlayer for invalid dist DEDICATED_SERVER Level level = Minecraft.getInstance().level; RandomSource rdm = RandomSource.create(); float r = rdm.nextInt(80, 120) / 100f; player.playSound(SoundEvents.LLAMA_SPIT, 1f, r); Vec3 MausPos = player.getEyePosition(); Vec3 SchauWinkel = player.getLookAngle(); level.addParticle(ParticleTypes.SPIT, true, MausPos.x, MausPos.y, MausPos.z, SchauWinkel.x/4, SchauWinkel.y/4, SchauWinkel.z/4); }); return true; } } Is there an alternative to Minecraft.getInstance().player;? dumb question. I have looked at other mods (MrCrayfish's Gun Mod, Ars Noveau, Apotheosis) on how they handle such server-to-client sound and particles but I haven't got any wiser.    
    • i keep getting error on minecraft when im trying to play modpack. When i go to logs folder i got this. 
    • Try an older build: https://www.curseforge.com/minecraft/mc-mods/sorceryfight/files/5358535
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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