Jump to content

[1.14.4] how to make a gui progress bar?


Kenneth201998

Recommended Posts

As I've started on a number of occasions:

Nothing prevents you from performing the cooking operation on the client, provided you synchronize the test of the data when appropriate. 

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

2 hours ago, Kenneth201998 said:

the arrow and flame

Instead of drawing a whole arrow/flame, draw (progress / total) of the arrow/flame. You can still use the same textured-rectangle-drawing method you always use. You can always look in some source classes to get a better idea of what you're doing, too.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

5 hours ago, Kenneth201998 said:

Im talking about the arrow and flame you see in the furnace gui... 

Wow, what a surprise.

So am I.

See this line here? Notice that this executes even when isRemote is true? That's because the client utilizes the same logic the server uses to update the smelting arrow.

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/client/gui/SifterGuiContainer.java#L46

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/entity/SifterTileEntity.java#L182

Edited by Draco18s

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

10 hours ago, Draco18s said:

Wow, what a surprise.

So am I.

See this line here? Notice that this executes even when isRemote is true? That's because the client utilizes the same logic the server uses to update the smelting arrow.

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/client/gui/SifterGuiContainer.java#L46

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/entity/SifterTileEntity.java#L182

where does the 40 come from in you blit function?

Link to comment
Share on other sites

Can you help me with this? I am not sure where you are getting your numbers in you blit function from but I can give you the GUI I created so you can help me get those numbers:

smelting_furnace_gui_1.png

There is a free program:

https://pixlr.com/editor/

It allows you to see the coordinates of each pixel by hovering over the image.

 

Edited by Kenneth201998
Link to comment
Share on other sites

2 hours ago, Kenneth201998 said:

where does the 40 come from in you blit function?

That happens to be the maximum time:

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/entity/SifterTileEntity.java#L90

Timer gets set to 40 and it counts down (values like this one being more as "abort, wait for valid inputs")

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

Ok so I have:

package com.kenneths_medieval_mod.objects.blocks.workstations.smelting_forge;

import org.lwjgl.opengl.GL11;

import com.kenneths_medieval_mod.KenmodMain;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;

public class SmeltingForgeGUI extends ContainerScreen<SmeltingForgeContainer> {
	
	SmeltingForgeTileEntity tile_entity;
	
	private static final ResourceLocation texture = new ResourceLocation("kenmod:textures/gui/smelting_forge_gui_1.png");
	
	public SmeltingForgeGUI(SmeltingForgeContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
		super(screenContainer, inv, titleIn);
		this.xSize = 176;
		this.ySize = 166;
		this.tile_entity = (SmeltingForgeTileEntity)screenContainer.tile_entity;
	}
	@Override
	public void render(int mouseX, int mouseY, float partialTicks) {
		this.renderBackground();
		super.render(mouseX, mouseY, partialTicks);
		this.renderHoveredToolTip(mouseX, mouseY);
	}
	@Override
	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		Minecraft.getInstance().getTextureManager().bindTexture(texture);
		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		this.blit(k, l, 0, 0, this.xSize, this.ySize);
		
		if(tile_entity != null) {
			//int burn_time = Math.round(24 * (100 - tile_entity.getBurnTime()) / 100);
			int cook_progress = Math.round(24 / tile_entity.getCookProgress());
			int le = this.guiLeft;
			int to = this.guiTop;
			
			//this.blit(le + 17, to + 40, 176, 14, burn_time + 1, 16);
			this.blit(le + 67, to + 39, 176, 14, cook_progress + 1, 16);
		}
	}
	@Override
	public void tick() {
		super.tick();
	}
	@Override
	protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
		this.font.drawString("Smelting Forge", 16, 5, -1);
	}
	@Override
	public void removed() {
		super.removed();
		Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
	}
	@Override
	public void init(Minecraft minecraft, int width, int height) {
		super.init(minecraft, width, height);
		minecraft.keyboardListener.enableRepeatEvents(true);
	}
}

And:

package com.kenneths_medieval_mod.objects.blocks.workstations.smelting_forge;

import com.kenneths_medieval_mod.objects.blocks.BlockList;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class SmeltingForgeTileEntity extends TileEntity implements ITickableTileEntity, INamedContainerProvider {
	
	protected ItemStackHandler slots = new ItemStackHandler();
	private final LazyOptional<IItemHandler> slots_holder = LazyOptional.of(() -> slots);
	private int burn_time;
	private int cook_progress;
	private int cook_goal = 200;
	
	public SmeltingForgeTileEntity() {
		super(BlockList.smelting_forge_tile_entity);
		slots = new ItemStackHandler();
		slots.setSize(4);
	}
	
	@Override
	public void tick() {
		//Fuel sent to the furnace has a max fuel life.
		if(burn_time < 1000 && slots.getStackInSlot(0) != ItemStack.EMPTY) {
			burn_time++;
			if(cook_progress < cook_goal) {
				cook_progress++;
			} else {
				cook_progress = 0;
			}
		} else {
			//When burn time reaches max fuel life get more fuel and reset the burn timer:
			burn_time = 0;
		}
	}
	
	public float getCookProgress () {
		return Math.round(cook_progress + 1 / cook_goal);
	}
	public int getBurnTime () {
		return burn_time;
	}
	
	@Override
	public void read(CompoundNBT tag) {
		super.read(tag);
		slots.deserializeNBT(tag.getCompound("kenmod:slots"));
		burn_time = tag.getInt("kenmod:burn_time");
		cook_progress = tag.getInt("kenmod:cook_progress");
	}
	@Override
	public CompoundNBT write(CompoundNBT tag) {
		super.write(tag);
		tag.put("kenmodlcb:slots", slots.serializeNBT());
		tag.putInt("kenmod:burn_time", burn_time);
		tag.putInt("kenmod:cook_progress", cook_progress);
		return tag;
	}
	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
		if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return slots_holder.cast();
		}
		return super.getCapability(cap, side);
	}
	@Override
	public Container createMenu(int id, PlayerInventory player_inventory, PlayerEntity player) {
		return new SmeltingForgeContainer(id, player_inventory, slots, this);
	}
	@Override
	public ITextComponent getDisplayName() {
		return new StringTextComponent("block.kenmodlcb.furnace_station");
	}
	
	public void openGUI (ServerPlayerEntity player) {
		if(!world.isRemote) {
			NetworkHooks.openGui(player, this, getPos());
		}
	}
}

But the arrow does not update. Whats wrong?

Link to comment
Share on other sites

You need to synchronize the data 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

Just to note, for simple data like an integer progress value, you can take advantage of the vanilla Container#trackInt() method to automatically sync values from server to client while the container is open.  The vanilla furnace uses it, and McJty has a tutorial about it here: https://wiki.mcjty.eu/modding/index.php?title=Tut14_Ep5 ("Showing Energy in GUI").

 

But beware - despite the method's name, it will only sync up to 16 bits of data - see SWindowPropertyPacket.  Shouldn't be a problem in this case, however.

  • Thanks 1
Link to comment
Share on other sites

I wonder if there are some methods in the tile entity class regarding update packets.

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

huh... this is odd:

when I use:

public float getCookProgress () {
	float test0 = cook_progress;
	KenmodMain.debugString("test0: " + test0);
	float test1 = cook_goal;
	KenmodMain.debugString("test1: " + test1);
	float test2 = ((float)cook_progress + 1.0F) / (float)cook_goal;
	KenmodMain.debugString("Get cook progress: " + test2);
	return test2;
}

the arrow updates, but only when I save and quit, and rejoin the world.

18 minutes ago, Draco18s said:

I wonder if there are some methods in the tile entity class regarding update packets.

package com.kenneths_medieval_mod.objects.blocks.workstations.smelting_forge;

import com.kenneths_medieval_mod.KenmodMain;
import com.kenneths_medieval_mod.objects.blocks.BlockList;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class SmeltingForgeTileEntity extends TileEntity implements ITickableTileEntity, INamedContainerProvider {
	
	protected ItemStackHandler slots = new ItemStackHandler();
	private final LazyOptional<IItemHandler> slots_holder = LazyOptional.of(() -> slots);
	private int burn_time;
	private int cook_progress;
	private int cook_goal = 200;
	
	public SmeltingForgeTileEntity() {
		super(BlockList.smelting_forge_tile_entity);
		slots = new ItemStackHandler();
		slots.setSize(4);
	}
	
	@Override
	public void tick() {
		//Fuel sent to the furnace has a max fuel life.
		if(burn_time < 1000 && slots.getStackInSlot(0) != ItemStack.EMPTY) {
			burn_time++;
			
			cook_progress++;
			KenmodMain.debugString("cp: " + cook_progress);
			if(cook_progress >= cook_goal) {
				cook_progress = 0;
			}
		} else {
			//When burn time reaches max fuel life get more fuel and reset the burn timer:
			burn_time = 0;
		}
		markDirty();
	}
	
	public float getCookProgress () {
		float test0 = cook_progress;
		KenmodMain.debugString("test0: " + test0);
		float test1 = cook_goal;
		KenmodMain.debugString("test1: " + test1);
		float test2 = ((float)cook_progress + 1.0F) / (float)cook_goal;
		KenmodMain.debugString("Get cook progress: " + test2);
		return test2;
	}
	public int getBurnTime () {
		return burn_time;
	}
	
	@Override
	public SUpdateTileEntityPacket getUpdatePacket() {
		return new SUpdateTileEntityPacket(this.pos, 0, this.getUpdateTag());
	}
	@Override
	public CompoundNBT getUpdateTag() {
		return this.write(new CompoundNBT());
	}
	@Override
	public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
		read(pkt.getNbtCompound());
	}
	
	@Override
	public void read(CompoundNBT tag) {
		super.read(tag);
		slots.deserializeNBT(tag.getCompound("kenmod:slots"));
		burn_time = tag.getInt("kenmod:burn_time");
		cook_progress = tag.getInt("kenmod:cook_progress");
	}
	@Override
	public CompoundNBT write(CompoundNBT tag) {
		super.write(tag);
		tag.put("kenmod:slots", slots.serializeNBT());
		tag.putInt("kenmod:burn_time", burn_time);
		tag.putInt("kenmod:cook_progress", cook_progress);
		return tag;
	}
	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
		if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return slots_holder.cast();
		}
		return super.getCapability(cap, side);
	}
	@Override
	public Container createMenu(int id, PlayerInventory player_inventory, PlayerEntity player) {
		return new SmeltingForgeContainer(id, player_inventory, slots, this);
	}
	@Override
	public ITextComponent getDisplayName() {
		return new StringTextComponent("block.kenmodlcb.furnace_station");
	}
	
	public void openGUI (ServerPlayerEntity player) {
		if(!world.isRemote) {
			NetworkHooks.openGui(player, this, getPos());
		}
	}
}

 

Link to comment
Share on other sites

43 minutes ago, Kenneth201998 said:

but only when I save and quit, and rejoin the world.

Because tile entity data is only "automatically" "synchronized" upon loading the world (quotes, because the way it works isn't really automatic and isn't really synchronizing, its just that certain vanilla calls regarding loading the TE from disk in single player has this net result).

 

44 minutes ago, Kenneth201998 said:

markDirty();

Don't do this every tick. Your burn time only really needs to be synchronized when the item slots change because your TE is already ticking the burn time on 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

13 hours ago, Kenneth201998 said:

This thing of getting the progress bar to update still eludes me. Know any example code? 

I will refer you to my previous comment in this thread.  Go and look up McJty's tutorial that I linked (although it's for syncing an energy value, the same principle of syncing an int value applies).  And also take a look at the vanilla furnace code, which uses that tracked int system.

Link to comment
Share on other sites

Ok. So I created my own capability known as Progress:

package com.kenneth.hard_survival_craft.objects.custom_capabilities;

public interface IProgress {
	void incrementProgress (int ammount);
	int getProgress ();
	void setProgress (int ammount);
}
package com.kenneth.hard_survival_craft.objects.custom_capabilities;

import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.common.util.INBTSerializable;

public class Progress implements IProgress, INBTSerializable<CompoundNBT> {
	
	protected int progress;
	
	public Progress(int progress) {
		this.progress = progress;
	}
	
	@Override
	public void incrementProgress(int ammount) {
		this.progress += ammount;
	}

	@Override
	public int getProgress() {
		return progress;
	}

	@Override
	public void setProgress(int ammount) {
		this.progress = ammount;
	}

	@Override
	public CompoundNBT serializeNBT() {
		CompoundNBT tag = new CompoundNBT();
		tag.putInt("progress", getProgress());
		return tag;
	}

	@Override
	public void deserializeNBT(CompoundNBT nbt) {
		setProgress(nbt.getInt("progress"));
	}
}
package com.kenneth.hard_survival_craft.objects.custom_capabilities;

import net.minecraft.nbt.INBT;
import net.minecraft.nbt.IntNBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;

public class CapabilityProgress {
	
	@CapabilityInject(IProgress.class)
	public static Capability<IProgress> PROGRESS = null;
	
	public static void register () {
		CapabilityManager.INSTANCE.register(IProgress.class, new Capability.IStorage<IProgress> () {
			@Override
			public INBT writeNBT(Capability<IProgress> capability, IProgress instance, Direction side) {
				return new IntNBT(instance.getProgress());
			}
			@Override
			public void readNBT(Capability<IProgress> capability, IProgress instance, Direction side, INBT nbt) {
				if(!(instance instanceof Progress)) {
					throw new IllegalArgumentException("Can not deserialize to an instance that isn't the default implementation");
				}
				((Progress)instance).progress = ((IntNBT)nbt).getInt();
			}
			
		}, () -> new Progress(0));
	}
	
}

Then I added it to my tile entity as so:

package com.kenneth.hard_survival_craft.objects.blocks.workstations.smelting_forge;

import com.kenneth.hard_survival_craft.KenmodMain;
import com.kenneth.hard_survival_craft.objects.blocks.BlockList;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.CapabilityProgress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.IProgress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.Progress;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class SmeltingForgeTileEntity extends TileEntity implements ITickableTileEntity, INamedContainerProvider {
	
	protected ItemStackHandler slots = new ItemStackHandler();
	private LazyOptional<IItemHandler> slots_holder = LazyOptional.of(() -> slots);
	private LazyOptional<IProgress> progress = LazyOptional.of(this::createProgress);
	
	private int burn_time;
	private int cook_progress;
	private int cook_goal = 200;
	
	public SmeltingForgeTileEntity() {
		super(BlockList.smelting_forge_tile_entity);
		slots = new ItemStackHandler();
		slots.setSize(4);
	}

	@Override
	public void tick() {
		//Fuel sent to the furnace has a max fuel life.
		if(burn_time < 1000 && slots.getStackInSlot(0) != ItemStack.EMPTY) {
			burn_time++;
			
			cook_progress++;
			getCookProgress();
			if(cook_progress >= cook_goal) {
				cook_progress = 0;
			}
		} else {
			//When burn time reaches max fuel life get more fuel and reset the burn timer:
			burn_time = 0;
		}
		markDirty();
	}
	
	public int getCookProgress() {
		int prog = this.getCapability(CapabilityProgress.PROGRESS).map(IProgress::getProgress).orElse(0) + 1;
		KenmodMain.debugString("Progress: " + prog);
		return prog;
	}
	public int getCookGoal () {
		KenmodMain.debugString("Cook Goal: " + cook_goal);
		return cook_goal;
	}
	
	private IProgress createProgress () {
		return new Progress(0);
	}
	
	@Override
	public SUpdateTileEntityPacket getUpdatePacket() {
		return new SUpdateTileEntityPacket(this.pos, 0, this.getUpdateTag());
	}
	@Override
	public CompoundNBT getUpdateTag() {
		return this.write(new CompoundNBT());
	}
	@Override
	public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
		read(pkt.getNbtCompound());
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public void read(CompoundNBT tag) {
		slots.deserializeNBT(tag.getCompound("slots"));
		CompoundNBT progressTag = tag.getCompound("progress");
		progress.ifPresent(h -> ((INBTSerializable<CompoundNBT>)h).deserializeNBT(progressTag));
		super.read(tag);
	}
	@SuppressWarnings("unchecked")
	@Override
	public CompoundNBT write(CompoundNBT tag) {
		tag.put("slots", slots.serializeNBT());
		progress.ifPresent(h -> {
			CompoundNBT compound = ((INBTSerializable<CompoundNBT>)h).serializeNBT();
			tag.put("progress", compound);
		});
		return super.write(tag);
	}
	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
		if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return slots_holder.cast();
		}
		if(cap == CapabilityProgress.PROGRESS) {
			return progress.cast();
		}
		return super.getCapability(cap, side);
	}
	@Override
	public Container createMenu(int id, PlayerInventory player_inventory, PlayerEntity player) {
		return new SmeltingForgeContainer(id, player_inventory, slots, this);
	}
	@Override
	public ITextComponent getDisplayName() {
		return new StringTextComponent("block.kenmodlcb.furnace_station");
	}
	
	public void openGUI (ServerPlayerEntity player) {
		if(!world.isRemote) {
			NetworkHooks.openGui(player, this, getPos());
		}
	}
}

And to the container:

package com.kenneth.hard_survival_craft.objects.blocks.workstations.smelting_forge;

import com.kenneth.hard_survival_craft.objects.blocks.BlockList;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.CapabilityProgress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.IProgress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.Progress;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.IntReferenceHolder;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.SlotItemHandler;

public class SmeltingForgeContainer extends Container {
	
	SmeltingForgeTileEntity tile_entity;
	
	@OnlyIn(Dist.CLIENT)
	public SmeltingForgeContainer (int id, PlayerInventory player_inventory, PacketBuffer extra_data) {
		this(id, player_inventory, new ItemStackHandler(4), (SmeltingForgeTileEntity)Minecraft.getInstance().world.getTileEntity(extra_data.readBlockPos()));
	}
	public SmeltingForgeContainer(int id, PlayerInventory player_inventory, IItemHandler smelting_forge_inventory, SmeltingForgeTileEntity te) {
		super(BlockList.smelting_forge_container, id);
		this.addSlot(new SlotItemHandler(smelting_forge_inventory, 0, 17, 21));
		this.addSlot(new SlotItemHandler(smelting_forge_inventory, 1, 44, 21));
		this.addSlot(new SlotItemHandler(smelting_forge_inventory, 2, 17, 57));
		this.addSlot(new SlotItemHandler(smelting_forge_inventory, 3, 98, 39) {
			@Override
			public boolean isItemValid(ItemStack stack) {
				return false;
			}
		});
		int si;
		int sj;
		for (si = 0; si < 3; ++si) {
			for (sj = 0; sj < 9; ++sj) {
				this.addSlot(new Slot(player_inventory, sj + (si + 1) * 9, 0 + 8 + sj * 18, 0 + 84 + si * 18));
			}
		}
		for (si = 0; si < 9; ++si) {
			this.addSlot(new Slot(player_inventory, si, 0 + 8 + si * 18, 0 + 142));
		}
		this.tile_entity = te;
		trackInt(new IntReferenceHolder() {
			@Override
			public void set(int value) {
				tile_entity.getCapability(CapabilityProgress.PROGRESS).ifPresent(h -> ((Progress)h).setProgress(value));
			}
			@Override
			public int get() {
				return getProgress();
			}
		});
	}
	@Override
	public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
		ItemStack itemstack = ItemStack.EMPTY;
		Slot slot = (Slot) this.inventorySlots.get(index);
		if (slot != null && slot.getHasStack()) {
			ItemStack itemstack1 = slot.getStack();
			itemstack = itemstack1.copy();
			if (index < 4) {
				if (!this.mergeItemStack(itemstack1, 4, this.inventorySlots.size(), true)) {
					return ItemStack.EMPTY;
				}
				slot.onSlotChange(itemstack1, itemstack);
			} else if (!this.mergeItemStack(itemstack1, 0, 4, false)) {
				if (index < 4 + 27) {
					if (!this.mergeItemStack(itemstack1, 4 + 27, this.inventorySlots.size(), true)) {
						return ItemStack.EMPTY;
					}
				} else {
					if (!this.mergeItemStack(itemstack1, 4, 4 + 27, false)) {
						return ItemStack.EMPTY;
					}
				}
				return ItemStack.EMPTY;
			}
			if (itemstack1.getCount() == 0) {
				slot.putStack(ItemStack.EMPTY);
			} else {
				slot.onSlotChanged();
			}
			if (itemstack1.getCount() == itemstack.getCount()) {
				return ItemStack.EMPTY;
			}
			slot.onTake(playerIn, itemstack1);
		}
		return itemstack;
	}
	@Override
	protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection) {
		boolean flag = false;
		int i = startIndex;
		if (reverseDirection) {
			i = endIndex - 1;
		}
		if (stack.isStackable()) {
			while (!stack.isEmpty()) {
				if (reverseDirection) {
					if (i < startIndex) {
						break;
					}
				} else if (i >= endIndex) {
					break;
				}
				Slot slot = this.inventorySlots.get(i);
				ItemStack itemstack = slot.getStack();
				if (slot.isItemValid(itemstack) && !itemstack.isEmpty() && areItemsAndTagsEqual(stack, itemstack)) {
					int j = itemstack.getCount() + stack.getCount();
					int maxSize = Math.min(slot.getSlotStackLimit(), stack.getMaxStackSize());
					if (j <= maxSize) {
						stack.setCount(0);
						itemstack.setCount(j);
						slot.putStack(itemstack);
						flag = true;
					} else if (itemstack.getCount() < maxSize) {
						stack.shrink(maxSize - itemstack.getCount());
						itemstack.setCount(maxSize);
						slot.putStack(itemstack);
						flag = true;
					}
				}
				if (reverseDirection) {
					--i;
				} else {
					++i;
				}
			}
		}
		if (!stack.isEmpty()) {
			if (reverseDirection) {
				i = endIndex - 1;
			} else {
				i = startIndex;
			}
			while (true) {
				if (reverseDirection) {
					if (i < startIndex) {
						break;
					}
				} else if (i >= endIndex) {
					break;
				}
				Slot slot1 = this.inventorySlots.get(i);
				ItemStack itemstack1 = slot1.getStack();
				if (itemstack1.isEmpty() && slot1.isItemValid(stack)) {
					if (stack.getCount() > slot1.getSlotStackLimit()) {
						slot1.putStack(stack.split(slot1.getSlotStackLimit()));
					} else {
						slot1.putStack(stack.split(stack.getCount()));
					}
					slot1.onSlotChanged();
					flag = true;
					break;
				}
				if (reverseDirection) {
					--i;
				} else {
					++i;
				}
			}
		}
		return flag;
	}
	public int getProgress () {
		return tile_entity.getCapability(CapabilityProgress.PROGRESS).map(IProgress::getProgress).orElse(0);
	}
	public int getGoal () {
		return tile_entity.getCookGoal();
	}
	@Override
	public void onContainerClosed(PlayerEntity playerIn) {
		super.onContainerClosed(playerIn);
	}
	@Override
	public boolean canInteractWith(PlayerEntity playerIn) {
		return true;
	}
}

And the gui screen:

package com.kenneth.hard_survival_craft.objects.blocks.workstations.smelting_forge;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;

public class SmeltingForgeGUI extends ContainerScreen<SmeltingForgeContainer> {
	
	private static final ResourceLocation texture = new ResourceLocation("kenmod:textures/gui/smelting_forge_gui.png");
	
	public SmeltingForgeGUI(SmeltingForgeContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
		super(screenContainer, inv, titleIn);
		this.xSize = 176;
		this.ySize = 166;
	}
	
	@Override
	public void render(int mouseX, int mouseY, float partialTicks) {
		this.renderBackground();
		super.render(mouseX, mouseY, partialTicks);
		this.renderHoveredToolTip(mouseX, mouseY);
	}
	@Override
	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		Minecraft.getInstance().getTextureManager().bindTexture(texture);
		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		this.blit(k, l, 0, 0, this.xSize, this.ySize);
		
		int cook_progress = Math.round(24 * getCookProgressScaled());
		int le = this.guiLeft;
		int to = this.guiTop;
		this.blit(le + 67, to + 39, 176, 14, cook_progress + 1, 16);
	}
	private float getCookProgressScaled () {
		int prog = container.getProgress();
		int goal = container.getGoal();
		return (float)prog / (float) goal;
	}
	@Override
	protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
		this.font.drawString("Smelting Forge", 16, 5, -1);
	}
	@Override
	public void tick() {
		super.tick();
	}
	@Override
	public void removed() {
		super.removed();
		Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
	}
	@Override
	public void init(Minecraft minecraft, int width, int height) {
		super.init(minecraft, width, height);
		minecraft.keyboardListener.enableRepeatEvents(true);
	}
}

However it sill does not update the progress bar. And when the line: 

KenmodMain.debugString("Progress: " + prog);

is called in my tile entity it still returns 1.

 

Still need help with this. Can someone at least tell me if I am getting close?

Link to comment
Share on other sites

Ok I have ran into one more problem:

package com.kenneth.hard_survival_craft.objects.blocks.workstations.smelting_forge;

import com.kenneth.hard_survival_craft.objects.blocks.BlockList;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityProgress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityProgressGoal;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityBurnTime;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.IProgress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.IProgressGoal;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.IBurnTime;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.Progress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.ProgressGoal;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.BurnTime;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class SmeltingForgeTileEntity extends TileEntity implements ITickableTileEntity, INamedContainerProvider {
	
	protected ItemStackHandler slots = new ItemStackHandler();
	private LazyOptional<IItemHandler> slots_holder = LazyOptional.of(() -> slots);
	private LazyOptional<IProgress> progress = LazyOptional.of(this::createProgress);
	private LazyOptional<IProgressGoal> progress_goal = LazyOptional.of(this::createGoal);
	private LazyOptional<IBurnTime> burn_time = LazyOptional.of(this::createBurnTime);
	
	public SmeltingForgeTileEntity() {
		super(BlockList.smelting_forge_tile_entity);
		slots = new ItemStackHandler();
		slots.setSize(4);
	}

	@Override
	public void tick() {
		
		if(getProgressGoal() != 300) {
			setGoal(300);
		}
		
		if(itemsValid() && (getBurnTime() > 0 || hasFuel())) {
			incrementProgress(1);
			if(getProgress() >= getProgressGoal()) {
				smelt();
				setProgress(0);
			}
		} else if (getProgress() > 0){
			decrementProgress(1);
		}
		
		
		//Decrement burn time:
		if(getBurnTime() > 0) {
			decrementBurn(1);
		} else if (hasFuel() && itemsValid()) {
			//If burn time reaches zero and there is still fuel and there is items left to smelt then reset the burn time:
			setBurn(400);
			slots.getStackInSlot(2).shrink(1);
		}
		
		if(isBurning() && world.getBlockState(pos).get(SmeltingForge.LIT) == false) {
			world.setBlockState(pos, world.getBlockState(pos).with(SmeltingForge.LIT, true).with(SmeltingForge.FACING, world.getBlockState(pos).get(SmeltingForge.FACING)));
		} else if (!isBurning() && world.getBlockState(pos).get(SmeltingForge.LIT) == true){
			world.setBlockState(pos, world.getBlockState(pos).with(SmeltingForge.LIT, false).with(SmeltingForge.FACING, world.getBlockState(pos).get(SmeltingForge.FACING)));
		}
		
		markDirty();
	}
	
	public boolean isBurning () {
		return getBurnTime() > 0 || (hasFuel() && itemsValid());
	}
	
	//Check if there is fuel left in slot 2:
	private boolean hasFuel () {
		if(slots.getStackInSlot(2).getItem() == Items.COAL || slots.getStackInSlot(2).getItem() == Items.CHARCOAL) {
			return true;
		}
		return false;
	}
	
	//Check if the inventory has proper items for smelting:
	private boolean itemsValid () {
		if(slots.getStackInSlot(0).getItem() == Items.IRON_INGOT && ((slots.getStackInSlot(3).getItem() == Items.GOLD_INGOT && slots.getStackInSlot(3).getCount() < slots.getStackInSlot(3).getMaxStackSize()) || slots.getStackInSlot(3) == ItemStack.EMPTY) && (slots.getStackInSlot(1).getItem() == Items.COAL || slots.getStackInSlot(1).getItem() == Items.CHARCOAL)) {
			return true;
		}
		return false;
	}
	//Smelt something:
	private void smelt () {
		if(slots.getStackInSlot(3) == ItemStack.EMPTY) {
			slots.setStackInSlot(3, new ItemStack(Items.GOLD_INGOT, 1));
		} else {
			slots.getStackInSlot(3).setCount(slots.getStackInSlot(3).getCount() + 1);
		}
		slots.getStackInSlot(0).shrink(1);
		slots.getStackInSlot(1).shrink(1);
	}
	
	public int getProgress() {
		int prog = this.getCapability(CapabilityProgress.PROGRESS).map(IProgress::getProgress).orElse(0);
		return prog;
	}
	public int getProgressGoal () {
		int goal = this.getCapability(CapabilityProgressGoal.PROGRESS_GOAL).map(IProgressGoal::getGoal).orElse(0) + 1;
		return goal;
	}
	public int getBurnTime () {
		int burn = this.getCapability(CapabilityBurnTime.BURN_TIME).map(IBurnTime::getBurnTime).orElse(0);
		return burn;
	}
	private void incrementProgress (int amount) {
		progress.ifPresent(p -> ((Progress)p).incrementProgress(amount));
	}
	private void decrementProgress (int amount) {
		progress.ifPresent(p -> ((Progress)p).decrementProgress(amount));
	}
	private void setProgress (int amount) {
		progress.ifPresent(p -> ((Progress)p).setProgress(amount));
	}
	private void setGoal (int amount) {
		progress_goal.ifPresent(g -> ((ProgressGoal)g).setGoal(amount));
	}
	private void decrementBurn (int amount) {
		burn_time.ifPresent(b -> ((BurnTime)b).decrementBurnTime(amount));
	}
	private void setBurn (int amount) {
		burn_time.ifPresent(b -> ((BurnTime)b).setBurnTime(amount));
	}
	
	private IProgress createProgress () {
		return new Progress(0);
	}
	private IProgressGoal createGoal () {
		return new ProgressGoal(0);
	}
	private IBurnTime createBurnTime () {
		return new BurnTime(0);
	}
	
	@Override
	public SUpdateTileEntityPacket getUpdatePacket() {
		return new SUpdateTileEntityPacket(this.pos, 0, this.getUpdateTag());
	}
	@Override
	public CompoundNBT getUpdateTag() {
		return this.write(new CompoundNBT());
	}
	@Override
	public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
		read(pkt.getNbtCompound());
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public void read(CompoundNBT tag) {
		slots.deserializeNBT(tag.getCompound("slots"));
		CompoundNBT progressTag = tag.getCompound("progress");
		CompoundNBT progessGoalTag = tag.getCompound("progress_goal");
		CompoundNBT burnTimeTag = tag.getCompound("burn_time");
		progress.ifPresent(h -> ((INBTSerializable<CompoundNBT>)h).deserializeNBT(progressTag));
		progress_goal.ifPresent(i -> ((INBTSerializable<CompoundNBT>)i).deserializeNBT(progessGoalTag));
		burn_time.ifPresent(j -> ((INBTSerializable<CompoundNBT>)j).deserializeNBT(burnTimeTag));
		super.read(tag);
	}
	@SuppressWarnings("unchecked")
	@Override
	public CompoundNBT write(CompoundNBT tag) {
		tag.put("slots", slots.serializeNBT());
		progress.ifPresent(h -> {
			CompoundNBT compound = ((INBTSerializable<CompoundNBT>)h).serializeNBT();
			tag.put("progress", compound);
		});
		progress_goal.ifPresent(i -> {
			CompoundNBT compound = ((INBTSerializable<CompoundNBT>)i).serializeNBT();
			tag.put("progress_goal", compound);
		});
		burn_time.ifPresent(j -> {
			CompoundNBT compound = ((INBTSerializable<CompoundNBT>)j).serializeNBT();
			tag.put("burn_time", compound);
		});
		return super.write(tag);
	}
	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
		if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return slots_holder.cast();
		}
		if(cap == CapabilityProgress.PROGRESS) {
			return progress.cast();
		}
		if(cap == CapabilityProgressGoal.PROGRESS_GOAL) {
			return progress_goal.cast();
		}
		if(cap == CapabilityBurnTime.BURN_TIME) {
			return burn_time.cast();
		}
		return super.getCapability(cap, side);
	}
	@Override
	public Container createMenu(int id, PlayerInventory player_inventory, PlayerEntity player) {
		return new SmeltingForgeContainer(id, player_inventory, slots, this);
	}
	@Override
	public ITextComponent getDisplayName() {
		return new StringTextComponent("block.kenmodlcb.furnace_station");
	}
	
	public void openGUI (ServerPlayerEntity player) {
		if(!world.isRemote) {
			NetworkHooks.openGui(player, this, getPos());
		}
	}
	
	@Override
	public void remove() {
		super.remove();
		slots_holder.invalidate();
		progress.invalidate();
		progress_goal.invalidate();
		burn_time.invalidate();
	}
	
	public void onDestroyed () {
		
		for(int i = 0; i < 4; i++) {
			if(slots.getStackInSlot(i) != ItemStack.EMPTY) {
				InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), slots.getStackInSlot(i));
			}
		}
	}
}

 

package com.kenneth.hard_survival_craft.objects.blocks.workstations.smelting_forge;

//import com.kenneth.hard_survival_craft.KenmodMain;
import com.kenneth.hard_survival_craft.objects.blocks.BlockList;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.BurnTime;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityBurnTime;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityProgress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.CapabilityProgressGoal;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.IProgress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.Progress;
import com.kenneth.hard_survival_craft.objects.custom_capabilities.block_capabilites.ProgressGoal;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.IntReferenceHolder;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.SlotItemHandler;

public class SmeltingForgeContainer extends Container {
	
	SmeltingForgeTileEntity tile_entity;
	
	@OnlyIn(Dist.CLIENT)
	public SmeltingForgeContainer (int id, PlayerInventory player_inventory, PacketBuffer extra_data) {
		this(id, player_inventory, new ItemStackHandler(4), (SmeltingForgeTileEntity)Minecraft.getInstance().world.getTileEntity(extra_data.readBlockPos()));
	}
	public SmeltingForgeContainer(int id, PlayerInventory player_inventory, IItemHandler smelting_forge_inventory, SmeltingForgeTileEntity te) {
		super(BlockList.smelting_forge_container, id);
		this.addSlot(new SlotItemHandler(smelting_forge_inventory, 0, 17, 21));
		this.addSlot(new SlotItemHandler(smelting_forge_inventory, 1, 44, 21));
		this.addSlot(new SlotItemHandler(smelting_forge_inventory, 2, 17, 57));
		this.addSlot(new SlotItemHandler(smelting_forge_inventory, 3, 98, 39) {
			@Override
			public boolean isItemValid(ItemStack stack) {
				return false;
			}
		});
		int si;
		int sj;
		for (si = 0; si < 3; ++si) {
			for (sj = 0; sj < 9; ++sj) {
				this.addSlot(new Slot(player_inventory, sj + (si + 1) * 9, 0 + 8 + sj * 18, 0 + 84 + si * 18));
			}
		}
		for (si = 0; si < 9; ++si) {
			this.addSlot(new Slot(player_inventory, si, 0 + 8 + si * 18, 0 + 142));
		}
		this.tile_entity = te;
		trackInt(new IntReferenceHolder() {
			@Override
			public void set(int value) {
				tile_entity.getCapability(CapabilityProgress.PROGRESS).ifPresent(h -> ((Progress)h).setProgress(value));
			}
			@Override
			public int get() {
				return getProgress();
			}
		});
		trackInt(new IntReferenceHolder() {
			@Override
			public void set(int value) {
				tile_entity.getCapability(CapabilityProgressGoal.PROGRESS_GOAL).ifPresent(h -> ((ProgressGoal)h).setGoal(value));
			}
			@Override
			public int get() {
				return getGoal();
			}
		});
		trackInt(new IntReferenceHolder() {
			@Override
			public void set(int value) {
				tile_entity.getCapability(CapabilityBurnTime.BURN_TIME).ifPresent(j -> ((BurnTime)j).setBurnTime(value));
			}
			@Override
			public int get() {
				return getBurnTime();
			}
		});
	}
	@Override
	public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
		ItemStack itemstack = ItemStack.EMPTY;
		Slot slot = (Slot) this.inventorySlots.get(index);
		if (slot != null && slot.getHasStack()) {
			ItemStack itemstack1 = slot.getStack();
			itemstack = itemstack1.copy();
			if (index < 4) {
				if (!this.mergeItemStack(itemstack1, 4, this.inventorySlots.size(), true)) {
					return ItemStack.EMPTY;
				}
				slot.onSlotChange(itemstack1, itemstack);
			} else if (!this.mergeItemStack(itemstack1, 0, 4, false)) {
				if (index < 4 + 27) {
					if (!this.mergeItemStack(itemstack1, 4 + 27, this.inventorySlots.size(), true)) {
						return ItemStack.EMPTY;
					}
				} else {
					if (!this.mergeItemStack(itemstack1, 4, 4 + 27, false)) {
						return ItemStack.EMPTY;
					}
				}
				return ItemStack.EMPTY;
			}
			if (itemstack1.getCount() == 0) {
				slot.putStack(ItemStack.EMPTY);
			} else {
				slot.onSlotChanged();
			}
			if (itemstack1.getCount() == itemstack.getCount()) {
				return ItemStack.EMPTY;
			}
			slot.onTake(playerIn, itemstack1);
		}
		return itemstack;
	}
	@Override
	protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection) {
		boolean flag = false;
		int i = startIndex;
		if (reverseDirection) {
			i = endIndex - 1;
		}
		if (stack.isStackable()) {
			while (!stack.isEmpty()) {
				if (reverseDirection) {
					if (i < startIndex) {
						break;
					}
				} else if (i >= endIndex) {
					break;
				}
				Slot slot = this.inventorySlots.get(i);
				ItemStack itemstack = slot.getStack();
				if (slot.isItemValid(itemstack) && !itemstack.isEmpty() && areItemsAndTagsEqual(stack, itemstack)) {
					int j = itemstack.getCount() + stack.getCount();
					int maxSize = Math.min(slot.getSlotStackLimit(), stack.getMaxStackSize());
					if (j <= maxSize) {
						stack.setCount(0);
						itemstack.setCount(j);
						slot.putStack(itemstack);
						flag = true;
					} else if (itemstack.getCount() < maxSize) {
						stack.shrink(maxSize - itemstack.getCount());
						itemstack.setCount(maxSize);
						slot.putStack(itemstack);
						flag = true;
					}
				}
				if (reverseDirection) {
					--i;
				} else {
					++i;
				}
			}
		}
		if (!stack.isEmpty()) {
			if (reverseDirection) {
				i = endIndex - 1;
			} else {
				i = startIndex;
			}
			while (true) {
				if (reverseDirection) {
					if (i < startIndex) {
						break;
					}
				} else if (i >= endIndex) {
					break;
				}
				Slot slot1 = this.inventorySlots.get(i);
				ItemStack itemstack1 = slot1.getStack();
				if (itemstack1.isEmpty() && slot1.isItemValid(stack)) {
					if (stack.getCount() > slot1.getSlotStackLimit()) {
						slot1.putStack(stack.split(slot1.getSlotStackLimit()));
					} else {
						slot1.putStack(stack.split(stack.getCount()));
					}
					slot1.onSlotChanged();
					flag = true;
					break;
				}
				if (reverseDirection) {
					--i;
				} else {
					++i;
				}
			}
		}
		return flag;
	}
	public int getProgress () {
		//KenmodMain.debugString("test 0: " + tile_entity.getProgress());
		return tile_entity.getCapability(CapabilityProgress.PROGRESS).map(IProgress::getProgress).orElse(0);
	}
	public int getGoal () {
		//KenmodMain.debugString("test 1: " + tile_entity.getProgressGoal());
		return tile_entity.getProgressGoal();
	}
	public int getBurnTime () {
		//KenmodMain.debugString("test 2: " + tile_entity.getBurnTime());
		return tile_entity.getBurnTime();
	}
	@Override
	public void onContainerClosed(PlayerEntity playerIn) {
		super.onContainerClosed(playerIn);
	}
	@Override
	public boolean canInteractWith(PlayerEntity playerIn) {
		return true;
	}
}

 

package com.kenneth.hard_survival_craft.objects.blocks.workstations.smelting_forge;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;

public class SmeltingForgeGUI extends ContainerScreen<SmeltingForgeContainer> {
	
	private static final ResourceLocation texture = new ResourceLocation("kenmod:textures/gui/smelting_forge_gui.png");
	
	public SmeltingForgeGUI(SmeltingForgeContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
		super(screenContainer, inv, titleIn);
		this.xSize = 176;
		this.ySize = 166;
	}
	
	@Override
	public void render(int mouseX, int mouseY, float partialTicks) {
		this.renderBackground();
		super.render(mouseX, mouseY, partialTicks);
		this.renderHoveredToolTip(mouseX, mouseY);
	}
	@Override
	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		Minecraft.getInstance().getTextureManager().bindTexture(texture);
		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		this.blit(k, l, 0, 0, this.xSize, this.ySize);
		
		int cook_progress = Math.round(24 * getCookProgressScaled());
		int le = this.guiLeft;
		int to = this.guiTop;
		this.blit(le + 67, to + 39, 176, 14, cook_progress + 1, 16);
		
		int burn_time = Math.round(13 - (13.0F * getBurnTimeScaled()));
		this.blit(le + 17, to + 39 + 13 - burn_time, 176, 12 - burn_time, 14, burn_time);
	}
	private float getBurnTimeScaled() {
		int burn = container.getBurnTime();
		int burn_goal = 400;
		if(burn_goal == 0) {
			return 0;
		} else {
			return 1.0F - ((float)burn / (float)burn_goal);
		}
	}
	private float getCookProgressScaled () {
		int prog = container.getProgress();
		int goal = container.getGoal();
		return (float)prog / (float) goal;
	}
	@Override
	protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
		this.font.drawString("Smelting Forge", 16, 5, -1);
	}
	@Override
	public void tick() {
		super.tick();
	}
	@Override
	public void removed() {
		super.removed();
		Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
	}
	@Override
	public void init(Minecraft minecraft, int width, int height) {
		super.init(minecraft, width, height);
		minecraft.keyboardListener.enableRepeatEvents(true);
	}
}

 

When looking at the progress arrow it will go forwards for a little bit, then jerk back a little, then continue going forward. What is causing this strangeness?

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

    • Did you check the getRenderShape method of your block to ensure it's returning the correct enum value?
    • new to messing with modpacks. the server starts and the pack is playable on personal worlds, but every time i try to enter the server, i get "internal exception: io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: Payload may not be larger than 1048576 bytes" and it boots me. not sure what this means. the debug log is essentially gibberish to me and i'm not sure... about anything. is it saying that it's sending me too much data? if it helps at all, my mc username is "leucanella", and the disconnect reasons are near the very bottom (at least once was due to mismatched modlists, but i got that fixed i'm pretty sure). i just can't make sense of it myself. https://gist.github.com/idlebird/c5269e80434a501104f6b99ebc16be46
    • We somehow figured out the issue: Whenever we try to eat a food item from the mod "[Let's Do] Candlelight" that can be eaten multiple times using a feeding upgrade from "Sophisticated Backpacks", that's when we crash. Food items include: - Beef Wellington - Bolognese - Chicken Alfredo - Chicken with Vegetables - Cooked Beef - Fricasse with Hash Browns - Lasagna - Lettuce with Steak - Lettuce with Tomatoes, Potatoes and Carrots - Mushroom Soup - Pasta with Bolognese - Pasta with Tomato Sauce - Pork Ribs - Roastbeef with Carrots - Salmon with White Wine Sauce - Tomato Mozzarella Salad - Tomato Soup - Tropical Fish Supreme
    • Me and my sister are playing on a modded minecraft server, but recently she has been crashing at random intervals and no one I've talked with knows why. There's no crash report on my sister's side, but in the log of the server there appears a bunch of lines every time she crashes. They appear to be mostly similar with different mods changing each crash. Minecraft Version: 1.20.1 Forge version: forge-47.2.20 Server log: [07May2024 18:13:29.067] [Server thread/ERROR] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: Exception caught during firing event: null     Index: 12     Listeners:         0: NORMAL         1: ASM: com.github.alexthe666.citadel.server.CitadelEvents@28c884eb onEntityUpdateDebug(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V         2: net.minecraftforge.eventbus.EventBus$$Lambda$4374/0x00007f0098c72da0@10f79ae2         3: ASM: com.github.alexthe666.alexsmobs.event.ServerEvents@6f4126f3 onLivingUpdateEvent(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V         4: ASM: class tallestegg.illagersweararmor.IWASpawnEvents tickEntity(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V         5: ASM: class io.github.lightman314.lightmanscurrency.common.EventHandler entityTick(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V         6: ASM: com.github.L_Ender.cataclysm.event.ServerEventHandler@1bbd60d8 onLivingUpdateEvent(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V         7: ASM: class io.github.edwinmindcraft.apoli.common.ApoliPowerEventHandler playerTick(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V         8: ASM: class io.github.edwinmindcraft.apoli.common.ApoliEventHandler livingTick(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V         9: net.minecraftforge.eventbus.EventBus$$Lambda$4374/0x00007f0098c72da0@1e30768c         10: ASM: class net.mcreator.borninchaosv.init.EntityAnimationFactory onEntityTick(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V         11: ASM: squeek.appleskin.network.SyncHandler@29e380f7 onLivingTickEvent(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V         12: ASM: top.theillusivec4.curios.common.event.CuriosEventHandler@55b4416c tick(Lnet/minecraftforge/event/entity/living/LivingEvent$LivingTickEvent;)V java.lang.ArrayIndexOutOfBoundsException [07May2024 18:13:29.146] [Server thread/WARN] [net.minecraft.server.network.ServerConnectionListener/]: Failed to handle packet for /OMITTED IP net.minecraft.ReportedException: Ticking player     at net.minecraft.server.level.ServerPlayer.m_9240_(ServerPlayer.java:530) ~[server-1.20.1-20230612.114412-srg.jar%23461!/:?]     at net.minecraft.server.network.ServerGamePacketListenerImpl.m_9933_(ServerGamePacketListenerImpl.java:262) ~[server-1.20.1-20230612.114412-srg.jar%23461!/:?]     at net.minecraft.network.Connection.m_129483_(Connection.java:263) ~[server-1.20.1-20230612.114412-srg.jar%23461!/:?]     at net.minecraft.server.network.ServerConnectionListener.m_9721_(ServerConnectionListener.java:142) ~[server-1.20.1-20230612.114412-srg.jar%23461!/:?]     at net.minecraft.server.MinecraftServer.m_5703_(MinecraftServer.java:907) ~[server-1.20.1-20230612.114412-srg.jar%23461!/:?]     at net.minecraft.server.dedicated.DedicatedServer.m_5703_(DedicatedServer.java:283) ~[server-1.20.1-20230612.114412-srg.jar%23461!/:?]     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:814) ~[server-1.20.1-20230612.114412-srg.jar%23461!/:?]     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23461!/:?]     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23461!/:?]     at java.lang.Thread.run(Thread.java:833) ~[?:?] Caused by: java.lang.ArrayIndexOutOfBoundsException Mod List: SecurityCraft v1.9.9.jar additional_lights-1.20.1-2.1.7.jar advancements_tracker_1.20.1-6.1.0.jar AI-Improvements-1.20-0.5.2.jar alexsdelight-1.5.jar alexsmobs-1.22.8.jar AmbientSounds_FORGE_v5.3.9_mc1.20.1.jar amendments-1.20-1.1.26.jar appleskin-forge-mc1.20.1-2.5.1.jar Aquaculture-1.20.1-2.5.1.jar aquaculture_delight_1.0.0_forge_1.20.1.jar architectury-9.2.14-forge.jar Arda's Sculks 1.3.2 [FORGE] [1.20.1].jar artifacts-forge-9.5.3.jar async-locator-forge-1.20-1.3.0.jar athena-forge-1.20.1-3.1.2.jar AttributeFix-Forge-1.20.1-21.0.4.jar BadOptimizations-2.1.1.jar badpackets-forge-0.4.3.jar balm-forge-1.20.1-7.2.2.jar beautify-2.0.2.jar BetterAdvancements-1.20.1-0.3.2.162.jar bettercombat-forge-1.8.5+1.20.1.jar BetterF3-7.0.2-Forge-1.20.1.jar betterfarmerscombat-1.2-1.20.1.jar BetterThirdPerson-Forge-1.20-1.9.0.jar BiomesOPlenty-1.20.1-18.0.0.598.jar Bookshelf-Forge-1.20.1-20.1.10.jar born_in_chaos_[Forge]1.20.1_1.2.jar Bountiful-6.0.3+1.20.1-forge.jar caelus-forge-3.2.0+1.20.1.jar camera-forge-1.20.1-1.0.8.jar canary-mc1.20.1-0.3.3.jar chat_heads-0.10.32-forge-1.20.jar Chimes-v2.0.1-1.20.1.jar Chipped-forge-1.20.1-3.0.6.jar chunksending-1.20.1-2.8.jar Chunky-1.3.136.jar citadel-2.5.4-1.20.1.jar cloth-config-11.1.118-forge.jar Clumps-forge-1.20.1-12.0.0.3.jar cluttered-2.1-1.20.1.jar connectedglass-1.1.11-forge-mc1.20.1.jar Controlling-forge-1.20.1-12.0.2.jar corpse-forge-1.20.1-1.0.12.jar cosmeticarmorreworked-1.20.1-v1a.jar CreativeCore_FORGE_v2.11.27_mc1.20.1.jar creeperoverhaul-3.0.2-forge.jar Croptopia-1.20.1-FORGE-3.0.4.jar ctia-1.20.1-forge-2.0.9.jar cupboard-1.20.1-2.6.jar curios-forge-5.9.0+1.20.1.jar CustomPlayerModels-1.20-0.6.16c.jar darktimer-forge-1.20.1-1.0.9.jar dotbe-1.20.1-1.5.5.jar dummmmmmy-1.20-1.8.14.jar DungeonsArise-1.20.x-2.1.58-release.jar DungeonsAriseSevenSeas-1.20.x-1.0.2-forge.jar dye_depot-1.0.0-forge.jar dynamiclights-v1.7.1-mc1.17x-1.20x-mod.jar easy_mob_farm_1.20.1-7.1.0.jar elevatorid-1.20.1-lex-1.9.jar embeddium-0.3.17+mc1.20.1-all.jar embeddiumplus-1.20.1-v1.2.8.jar emotecraft-for-MC1.20.1-2.2.7-b.build.50-forge.jar EnchantmentDescriptions-Forge-1.20.1-17.0.14.jar EnderMail-1.20.1-1.2.9.jar endermanoverhaul-forge-1.20.1-1.0.4.jar endersdelight-1.20.1-1.0.3.jar entityculling-forge-1.6.2-mc1.20.1.jar EpheroLib-1.20.1-FORGE-1.2.0.jar fantasyfurniture-1.20.1-9.0.0.jar FarmersDelight-1.20.1-1.2.4.jar farmersutils-1.0.5-1.20.1.jar Fastload-Reforged-mc1.20.1-3.4.0.jar fastpaintings-1.20-1.2.5.jar ferritecore-6.0.1-forge.jar friendsandfoes-forge-mc1.20.1-2.0.10.jar ftb-essentials-forge-2001.2.2.jar ftb-library-forge-2001.2.1.jar fusion-1.1.1-forge-mc1.20.1.jar geckolib-forge-1.20.1-4.4.4.jar getittogetherdrops-forge-1.20-1.3.jar handcrafted-forge-1.20.1-3.0.6.jar IllagerInvasion-v8.0.5-1.20.1-Forge.jar illagersweararmor-1.20.1-1.3.4.jar ImmediatelyFast-Forge-1.2.13+1.20.4.jar immersive_melodies-0.1.0+1.20.1-forge.jar Incendium_1.20.4_v5.3.4.jar Item_Obliterator-FORGE-MC1.20.1-1.7.0.jar Jade-1.20.1-forge-11.8.0.jar jei-1.20.1-forge-15.3.0.4.jar journeymap-1.20.1-5.9.20-forge.jar Kambrik-6.1.1+1.20.1-forge.jar kotlinforforge-4.10.0-all.jar L_Enders_Cataclysm-1.99.2 -1.20.1.jar LeavesBeGone-v8.0.0-1.20.1-Forge.jar letmedespawn-forge-1.20.x-1.2.0.jar letsdo-addon-compat-forge-v1.4.1.jar letsdo-API-forge-1.2.9-forge.jar letsdo-bakery-forge-1.1.8.jar letsdo-beachparty-forge-1.1.4-1.jar letsdo-brewery-forge-1.1.6.jar letsdo-candlelight-forge-1.2.11.jar letsdo-herbalbrews-forge-1.0.6.jar letsdo-meadow-forge-1.3.8.jar letsdo-nethervinery-forge-1.2.10.jar letsdo-vinery-forge-1.4.15.jar lightmanscurrency-1.20.1-2.2.1.3b.jar lionfishapi-1.8.jar magicvibedecorations-HALLOWEEN 1.5.0 1.20.1 forge.jar make_bubbles_pop-0.2.0-forge-mc1.19.4+.jar memoryleakfix-forge-1.17+-1.1.5.jar MobLassos-v8.0.1-1.20.1-Forge.jar modelfix-1.15.jar moonlight-1.20-2.11.14-forge.jar morediscs-1.20.1-33-forge.jar MouseTweaks-forge-mc1.20-2.25.jar Necronomicon-Forge-1.4.2.jar nether-s-exoticism-1.20.1-1.2.7.jar nethersdelight-1.20.1-4.0.jar nomowanderer-1.20.1_1.6.4.jar oculus-mc1.20.1-1.7.0.jar origins-forge-1.20.1-1.10.0.7-all.jar origins-plus-plus-2.2-forge.jar Paraglider-forge-20.1.3.jar Patchouli-1.20.1-84-FORGE.jar Paxi-1.20-Forge-4.0.jar Pehkui-3.8.0+1.20.1-forge.jar player-animation-lib-forge-1.0.2-rc1+1.20.jar PlayerRevive_FORGE_v2.0.24_mc1.20.1.jar plushies-1.4.0-forge.jar polymorph-forge-0.49.3+1.20.1.jar projectvibrantjourneys-1.20.1-6.0.0.jar PuzzlesLib-v8.1.18-1.20.1-Forge.jar resourcefulconfig-forge-1.20.1-2.1.2.jar resourcefullib-forge-1.20.1-2.1.24.jar right-click-harvest-3.2.3+1.20.1-forge.jar rubidium-extra-0.5.4.3+mc1.20.1-build.121.jar Runelic-Forge-1.20.1-18.0.2.jar saturn-mc1.20.1-0.1.3.jar sawmill-1.20-1.3.13.jar scholar-1.20.1-1.0.0-forge.jar screenshot_viewer-1.2.1-forge-mc1.20.1.jar Searchables-forge-1.20.1-1.0.2.jar selfexpression-2.8 1.20.1.jar servercore-forge-1.5.1+1.20.1.jar ShulkerArmory_1.20.1_1.2.1_hotfix.jar simplehats-forge-1.20.1-0.2.4.jar simplevoicechat_broadcast-mc1.20.1-1.0.1.jar simplyswords-forge-1.55.0-1.20.1.jar smoothboot(reloaded)-mc1.20.1-0.0.4.jar Sniffer+-forge-1.20.1-0.3.0.jar sophisticatedbackpacks-1.20.1-3.20.5.1044.jar sophisticatedcore-1.20.1-0.6.21.609.jar sophisticatedstorage-1.20.1-0.10.21.793.jar spark-1.10.53-forge.jar stalwart-dungeons-1.20.1-1.2.8.jar starlight-1.1.2+forge.1cda73c.jar step-1.20.1-1.2.2.jar supermartijn642corelib-1.1.17-forge-mc1.20.1.jar supplementaries-1.20-2.8.10.jar temporalapi-1.5.0.jar TerraBlender-forge-1.20.1-3.0.1.4.jar Terralith_1.20.4_v2.4.11.jar toms_storage-1.20-1.6.6.jar torchmaster-20.1.6.jar trashslot-forge-1.20-15.1.0.jar treasuredistance-1.20-1.2.jar tru.e-ending-v1.1.0c.jar v_slab_compat-1.20-2.3.jar vintagedelight-0.0.12.jar vmp-fabric-mc1.20.1-0.2.0+beta.7.101-all.jar voicechat-forge-1.20.1-2.5.11.jar waystones-forge-1.20-14.1.3.jar WI-Zoom-1.5-MC1.20.1-Forge.jar worldedit-mod-7.2.15.jar wsopulence1.2.0_Forge_MC1.20.1-1.20.4.jar xlpackets-1.18.2-2.1.jar YungsApi-1.20-Forge-4.0.4.jar YungsBetterEndIsland-1.20-Forge-2.0.6.jar YungsBetterNetherFortresses-1.20-Forge-2.0.6.jar YungsBetterOceanMonuments-1.20-Forge-3.0.4.jar YungsBetterStrongholds-1.20-Forge-4.0.3.jar
    • Like the title i wanted to render a obj model into minecraft but i cant find any tutorials for this.
  • Topics

×
×
  • Create New...

Important Information

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