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



×
×
  • Create New...

Important Information

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