Jump to content

[1.16.5] Furnace scaled progression bar with .blit not updating


bibouche_

Recommended Posts

Hi everyone, for my mod I wanted to do a custom furnace, everything works fine except the progression bar, indeed in the screen class, where I use the drawGuiContainerBackgroundLayer( ) function I put a blit with my progression bar, the problem I have is that I think it draws the texture once and then it is not updating, even if for the width I inserted a dynamic value that gives the width to display depending on the currentSmeltTime out of the MaxSmeltTime of the cooking. So my question would be : How can I make this updating and redrawing when the value changes ?

 

Here is the function which is called 

@Override
	protected void drawGuiContainerBackgroundLayer(
		MatrixStack matrixStack,
		float partialTicks,
		int mousex,
		int mousey) {
		RenderSystem.color4f(1f, 1f, 1f, 1f);
		this.minecraft.textureManager.bindTexture(FORGE_GUI);
		this.blit(matrixStack, this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);

		int l = this.container.getSmeltProgressionScaled();
		this.blit(matrixStack, this.guiLeft + 64, this.guiTop + 40, 176, 0, l + 1, 4);
	}

my problem is in the two last lines, may someone help me please ?

 

the getSmeltProgressionScaled( ) function (in my container class) 

@OnlyIn(Dist.CLIENT)
	public int getSmeltProgressionScaled() {
		return this.te.currentSmeltTime != 0 && this.te.smeltTime != 0 ? this.te.currentSmeltTime * 47 / this.te.smeltTime : 0;
	}

Thanks you for your help

Link to comment
Share on other sites

I deleted the @OnlyIn but it is not fixing the issue.

 

Here is my container class:

public class ForgeContainer extends Container {

	public final  ForgeTileEntity              te;
	private final IWorldPosCallable            canInteractWithCollable;
	public        FunctionalIntreferenceHolder currentSmeltTime;

	public ForgeContainer(final int windowId, final
	                      PlayerInventory playerInv, final ForgeTileEntity te) {
		super(ModContainers.FORGE_CONTAINER.get(), windowId);
		this.te = te;
		this.canInteractWithCollable = IWorldPosCallable.of(te.getWorld(), te.getPos());

		// Forge Inv
		this.addSlot(new ForgeUpgradableSlot(te, 0, 42, 34));
		this.addSlot(new ForgeFuelSlot( te, 1, 42, 63));
		this.addSlot(new ForgeCompressorSlot(te, 2, 81, 7));
		this.addSlot(new ForgeOutputSlot(te, 3, 117, 34));

		this.trackInt(currentSmeltTime = new FunctionalIntreferenceHolder(() -> this.te.currentSmeltTime, time -> this.te.currentSmeltTime = time));

		// Player Inv
		for (int row = 0; row < 3; row++) {
			for (int col = 0; col < 9; col++) {
				this.addSlot(new Slot(playerInv, col + row * 9 + 9, 8  + col * 18, 119 + (row * 18)));
			}
		}

		// Player HotBar
		for (int col = 0; col < 9; col++) {
			this.addSlot(new Slot(playerInv, col, 8 + col * 18, 177));
		}
	}

	public ForgeContainer(final int windowId, final
	PlayerInventory playerInv, final
	                      PacketBuffer data) {
		this(windowId, playerInv, getTileEntity(playerInv, data));
	}

	private static ForgeTileEntity getTileEntity(final PlayerInventory playerInv, final PacketBuffer data) {
		Objects.requireNonNull(playerInv, "player inventory cannot be null");
		Objects.requireNonNull(data, "packet buffer cannot be null");
		final TileEntity te = playerInv.player.world.getTileEntity(data.readBlockPos());

		if (te instanceof ForgeTileEntity) {
			return (ForgeTileEntity) te;
		}

		throw new IllegalStateException("Tile Entity is not correct");
	}

	@Override
	public boolean canInteractWith(
		PlayerEntity playerIn) {
		return isWithinUsableDistance(canInteractWithCollable, playerIn,
		                              ModBlocks.FORGE.get());
	}

	@Override
	public ItemStack transferStackInSlot(
		PlayerEntity playerIn,
		int index) {
		ItemStack stack = ItemStack.EMPTY;
		Slot slot = this.inventorySlots.get(index);

		if (slot != null && slot.getHasStack()) {
			ItemStack stack1 = slot.getStack();
			stack = stack1.copy();

			if (index < ForgeTileEntity.slots - 1 && !this.mergeItemStack(stack1, ForgeTileEntity.slots, this.inventorySlots.size(), true)) {
				return ItemStack.EMPTY;
			}
			if (!this.mergeItemStack(stack1, 0, ForgeTileEntity.slots, false)) {
				return ItemStack.EMPTY;
			}
			if (stack1.isEmpty()) {
				slot.putStack(ItemStack.EMPTY);
			}
			else {
				slot.onSlotChanged();
			}
		}

		return stack;

	}
	
	public int getSmeltProgressionScaled() {
		return this.currentSmeltTime.get() != 0 && this.te.smeltTime != 0 ? this.currentSmeltTime.get() * 47 / this.te.smeltTime : 0;
	}

}

 

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



×
×
  • Create New...

Important Information

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