Jump to content

[1.10.2] Gui doesn't update progress or RF storage[RESOLVED]


RealTheUnderTaker11

Recommended Posts

I have spent a stupid amount of hours trying to figure out how to make a tile entity that will work with a GUI and show progress/Stored energy. There isn't a whole lot on this at all so I've been using https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe31_inventory_furnace as well as some things from MCjty's tutorials to try and create this machine block. The tutorial code is given using IInventory so I have had to fumble my way around this whole thing to get it to work with capabilities instead.

 

Now that that's out of the way my problem is as the title says, it should be noted I know I changed the number of slots and the number of fires that would respond. I am planning to change the look of the texture later. Just know everything I put in place is working besides the fact shift click doesn't work, and nothing will update with how much power/ % progress. In fact it won't tell me the power at all, it always says it is 0. All related classes are below, I hope I don't miss one.

 

Block class- http://pastebin.com/NUcDeyJ3

Tile Entity Class(And the one it extends right below it)- http://pastebin.com/buBHi2wy

Container class-http://pastebin.com/yvijT51R

Gui class- http://pastebin.com/Rc92LtFG

 

GuiProxy class(A gui handler)

 

 

package com.theundertaker11.GeneticsReborn.proxy;

import com.theundertaker11.GeneticsReborn.blocks.cellanalyser.ContainerCellAnalyser;
import com.theundertaker11.GeneticsReborn.blocks.cellanalyser.GRTileEntityCellAnalyser;
import com.theundertaker11.GeneticsReborn.blocks.cellanalyser.GuiCellAnalyser;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

public class GuiProxy implements IGuiHandler{

@Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
        BlockPos pos = new BlockPos(x, y, z);
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof GRTileEntityCellAnalyser)
        {
            return new ContainerCellAnalyser(player.inventory, (GRTileEntityCellAnalyser) te);
        }
       //Add new if's for each gui
        return null;
    }

    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
    {
        TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
        if (te instanceof GRTileEntityCellAnalyser)
        {
            return new GuiCellAnalyser(player.inventory, (GRTileEntityCellAnalyser) te);
        }
        //Add new if's for each gui
        return null;
    }
}

 

Lastly the line of code I register the handler

NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiProxy());

 

I am more than open to any suggestions about how to do things better or what I'm doing wrong besides the topic problem(Such as the shift click).

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

Bump, I really want this solved so I can start on the other tile entities, I don't want to make a bunch of code for all of them just to learn I had something big wrong that one of you guys catches. Better safe than sorry

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

Did you know that there is an energy capability? net.minecraftforge.energy.CapabilityEnergy - I suggest using that. Also you can read about capabilities here http://mcforge.readthedocs.io/en/latest/datastorage/capabilities/, although it's not explanatory enough. If you have any questions about them, do ask, because I recently refactored my mod to use item and energy capabilities and dropped IInventory interfaces.

Link to comment
Share on other sites

Capabilities are not the problem though. Besides the  shift clicking the capability works perfect. My problem is the GUI not updating anything besides when the item is finished processing.(I put organic matter in the input, wait a bit, and a diamond pops up in the output.) It is using power, and it is storing its power just fine. I have enderIO in my env to test everything with.

Do most big RF mods use the forge energy system now? Most I've seen still have COFH in them so I felt it was safer to use that, be compatible with as many as possible.

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

Your problem is your setField, it doesn't set everything which is used to update the values on the client side.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

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

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

So now I changed that and made the progress one actually do math for the progress of the item its "burning"

 

But now it shows energy in the GUI until I put an item in. The second it start processing the item both values go back to 0 and stay there till it is finished. Is there some kind of GUI make I could use for when I end up making my own? GUI's make me sad.

 

GUI code-http://pastebin.com/hZiiqzj8

 

Tile Entity Code-http://pastebin.com/UfyN1h2M

 

and container code just in case, I don't think  I changed anything here though

 

package com.theundertaker11.GeneticsReborn.blocks.cellanalyser;

import com.theundertaker11.GeneticsReborn.items.GRItems;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

/**
 * User: brandon3055
 * Date: 06/01/2015
 *
 * ContainerSmelting is used to link the client side gui to the server side inventory and it is where
 * you add the slots holding items. It is also used to send server side data such as progress bars to the client
 * for use in guis
 */
public class ContainerCellAnalyser extends Container {

	// Stores the tile entity instance for later use
	private GRTileEntityCellAnalyser tileInventory;

	// These store cache values, used by the server to only update the client side tile entity when values have changed
	private int [] cachedFields;

	// must assign a slot index to each of the slots used by the GUI.
	// For this container, we can see the furnace fuel, input, and output slots as well as the player inventory slots and the hotbar.
	// Each time we add a Slot to the container using addSlotToContainer(), it automatically increases the slotIndex, which means
	//  0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 
	//  9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
	//  36 - 39 = fuel slots (tileEntity 0 - 3)
	//  40 - 44 = input slots (tileEntity 4 - 
	//  45 - 49 = output slots (tileEntity 9 - 13)

	private final int HOTBAR_SLOT_COUNT = 9;
	private final int PLAYER_INVENTORY_ROW_COUNT = 3;
	private final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
	private final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
	private final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;

	//public final int FUEL_SLOTS_COUNT = 4;
	public final int INPUT_SLOTS_COUNT = 1;
	public final int OUTPUT_SLOTS_COUNT = 1;
	public final int TOTAL_SLOTS_COUNT = INPUT_SLOTS_COUNT + OUTPUT_SLOTS_COUNT;

	// slot index is the unique index for all slots in this container i.e. 0 - 35 for invPlayer then 36 - 49 for tileInventory
	private final int VANILLA_FIRST_SLOT_INDEX = 0;
	//private final int FIRST_FUEL_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
	private final int INPUT_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
	private final int OUTPUT_SLOT_INDEX = INPUT_SLOT_INDEX + INPUT_SLOTS_COUNT;

	// slot number is the slot number within each component; i.e. invPlayer slots 0 - 35, and tileInventory slots 0 - 14
	//private final int FIRST_FUEL_SLOT_NUMBER = 0;
	private final int INPUT_SLOT_NUMBER = 0;
	private final int OUTPUT_SLOT_NUMBER = 0;

	public ContainerCellAnalyser(InventoryPlayer invPlayer, GRTileEntityCellAnalyser tileInventory){
		this.tileInventory = tileInventory;

		final int SLOT_X_SPACING = 18;
		final int SLOT_Y_SPACING = 18;
		final int HOTBAR_XPOS = 8;
		final int HOTBAR_YPOS = 183;
		// Add the players hotbar to the gui - the [xpos, ypos] location of each item
		for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) {
			int slotNumber = x;
			addSlotToContainer(new Slot(invPlayer, slotNumber, HOTBAR_XPOS + SLOT_X_SPACING * x, HOTBAR_YPOS));
		}

		final int PLAYER_INVENTORY_XPOS = 8;
		final int PLAYER_INVENTORY_YPOS = 125;
		// Add the rest of the players inventory to the gui
		for (int y = 0; y < PLAYER_INVENTORY_ROW_COUNT; y++) {
			for (int x = 0; x < PLAYER_INVENTORY_COLUMN_COUNT; x++) {
				int slotNumber = HOTBAR_SLOT_COUNT + y * PLAYER_INVENTORY_COLUMN_COUNT + x;
				int xpos = PLAYER_INVENTORY_XPOS + x * SLOT_X_SPACING;
				int ypos = PLAYER_INVENTORY_YPOS + y * SLOT_Y_SPACING;
				addSlotToContainer(new Slot(invPlayer, slotNumber,  xpos, ypos));
			}
		}
		/*
		final int FUEL_SLOTS_XPOS = 53;
		final int FUEL_SLOTS_YPOS = 96;
		// Add the tile fuel slots
		for (int x = 0; x < FUEL_SLOTS_COUNT; x++) {
			int slotNumber = x + FIRST_FUEL_SLOT_NUMBER;
			addSlotToContainer(new SlotFuel(tileInventory, slotNumber, FUEL_SLOTS_XPOS + SLOT_X_SPACING * x, FUEL_SLOTS_YPOS));
		}
		*/
		IItemHandler itemhandlerinput = tileInventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
		IItemHandler itemhandleroutput = tileInventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
		final int INPUT_SLOTS_XPOS = 26;
		final int INPUT_SLOTS_YPOS = 24;
		// Add the tile input slots
		for (int y = 0; y < INPUT_SLOTS_COUNT; y++) {
			int slotNumber = y + INPUT_SLOT_NUMBER;
			addSlotToContainer(new SlotSmeltableInput(itemhandlerinput, slotNumber, INPUT_SLOTS_XPOS, INPUT_SLOTS_YPOS+ SLOT_Y_SPACING * y));
		}

		final int OUTPUT_SLOTS_XPOS = 134;
		final int OUTPUT_SLOTS_YPOS = 24;
		// Add the tile output slots
		for (int y = 0; y < OUTPUT_SLOTS_COUNT; y++) {
			int slotNumber = y + OUTPUT_SLOT_NUMBER;
			addSlotToContainer(new SlotOutput(itemhandleroutput, slotNumber, OUTPUT_SLOTS_XPOS, OUTPUT_SLOTS_YPOS + SLOT_Y_SPACING * y));
		}
	}

	// Checks each tick to make sure the player is still able to access the inventory and if not closes the gui
	@Override
	public boolean canInteractWith(EntityPlayer player)
	{
		return tileInventory.isUseableByPlayer(player);
	}

	// This is where you specify what happens when a player shift clicks a slot in the gui
	//  (when you shift click a slot in the TileEntity Inventory, it moves it to the first available position in the hotbar and/or
	//    player inventory.  When you you shift-click a hotbar or player inventory item, it moves it to the first available
	//    position in the TileEntity inventory - either input or fuel as appropriate for the item you clicked)
	// At the very least you must override this and return null or the game will crash when the player shift clicks a slot
	// returns null if the source slot is empty, or if none of the source slot items could be moved.
	//   otherwise, returns a copy of the source stack
	@Override
	public ItemStack transferStackInSlot(EntityPlayer player, int sourceSlotIndex)
	{
		ItemStack itemstack = null;
        Slot slot = this.inventorySlots.get(sourceSlotIndex);

        if (slot != null && slot.getHasStack()) {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (sourceSlotIndex < GRTileEntityCellAnalyser.getSIZE()) {
                if (!this.mergeItemStack(itemstack1, GRTileEntityCellAnalyser.getSIZE(), this.inventorySlots.size(), true)) {
                    return null;
                }
            }else if (!this.mergeItemStack(itemstack1, 0, GRTileEntityCellAnalyser.getSIZE(), false)) {
                return null;
            }

            if (itemstack1.stackSize == 0) {
                slot.putStack(null);
            } else {
                slot.onSlotChanged();
            }
        }
        return itemstack;
		/*
		Slot sourceSlot = (Slot)inventorySlots.get(sourceSlotIndex);
		if (sourceSlot == null || !sourceSlot.getHasStack()) return null;
		ItemStack sourceStack = sourceSlot.getStack();
		ItemStack copyOfSourceStack = sourceStack.copy();

		// Check if the slot clicked is one of the vanilla container slots
		if (sourceSlotIndex >= VANILLA_FIRST_SLOT_INDEX && sourceSlotIndex < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
			// This is a vanilla container slot so merge the stack into one of the furnace slots
			// If the stack is smeltable try to merge merge the stack into the input slots
			if (GRTileEntityCellAnalyser.getSmeltingResultForItem(sourceStack) != null){
				if (!mergeItemStack(sourceStack, FIRST_INPUT_SLOT_INDEX, FIRST_INPUT_SLOT_INDEX + INPUT_SLOTS_COUNT, false)){
					return null;
				}
			}	else if (GRTileEntityCellAnalyser.getItemBurnTime(sourceStack) > 0) {
				if (!mergeItemStack(sourceStack, FIRST_FUEL_SLOT_INDEX, FIRST_FUEL_SLOT_INDEX + FUEL_SLOTS_COUNT, true)) {
					// Setting the boolean to true places the stack in the bottom slot first
					return null;
				}
			}	else {
				return null;
			}
		} else if (sourceSlotIndex >= FIRST_FUEL_SLOT_INDEX && sourceSlotIndex < FIRST_FUEL_SLOT_INDEX + FURNACE_SLOTS_COUNT) {
			// This is a furnace slot so merge the stack into the players inventory: try the hotbar first and then the main inventory
			//   because the main inventory slots are immediately after the hotbar slots, we can just merge with a single call
			if (!mergeItemStack(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) {
				return null;
			}
		} else {
			System.err.print("Invalid slotIndex:" + sourceSlotIndex);
			return null;
		}

		// If stack size == 0 (the entire stack was moved) set slot contents to null
		if (sourceStack.stackSize == 0) {
			sourceSlot.putStack(null);
		} else {
			sourceSlot.onSlotChanged();
		}

		sourceSlot.onPickupFromSlot(player, sourceStack);
		return copyOfSourceStack;
		*/
	}

	/* Client Synchronization */

	// This is where you check if any values have changed and if so send an update to any clients accessing this container
	// The container itemstacks are tested in Container.detectAndSendChanges, so we don't need to do that
	// We iterate through all of the TileEntity Fields to find any which have changed, and send them.
	// You don't have to use fields if you don't wish to; just manually match the ID in sendProgressBarUpdate with the value in
	//   updateProgressBar()
	// The progress bar values are restricted to shorts.  If you have a larger value (eg int), it's not a good idea to try and split it
	//   up into two shorts because the progress bar values are sent independently, and unless you add synchronisation logic at the
	//   receiving side, your int value will be wrong until the second short arrives.  Use a custom packet instead.
	@Override
	public void detectAndSendChanges() {
		super.detectAndSendChanges();

		boolean allFieldsHaveChanged = false;
		boolean fieldHasChanged [] = new boolean[tileInventory.getFieldCount()];
		if (cachedFields == null) {
			cachedFields = new int[tileInventory.getFieldCount()];
			allFieldsHaveChanged = true;
		}
		for (int i = 0; i < cachedFields.length; ++i) {
			if (allFieldsHaveChanged || cachedFields[i] != tileInventory.getField(i)) {
				cachedFields[i] = tileInventory.getField(i);
				fieldHasChanged[i] = true;
			}
		}

	// go through the list of listeners (players using this container) and update them if necessary
    for (IContainerListener listener : this.listeners) {
			for (int fieldID = 0; fieldID < tileInventory.getFieldCount(); ++fieldID) {
				if (fieldHasChanged[fieldID])
				{
					// Note that although sendProgressBarUpdate takes 2 ints on a server these are truncated to shorts
					listener.sendProgressBarUpdate(this, fieldID, cachedFields[fieldID]);
				}
			}
		}
	}

	// Called when a progress bar update is received from the server. The two values (id and data) are the same two
	// values given to sendProgressBarUpdate.  In this case we are using fields so we just pass them to the tileEntity.
	@SideOnly(Side.CLIENT)
	@Override
	public void updateProgressBar(int id, int data) {
		tileInventory.setField(id, data);
	}

	// SlotFuel is a slot for fuel items
	/*public class SlotFuel extends Slot {
		public SlotFuel(IInventory inventoryIn, int index, int xPosition, int yPosition) {
			super(inventoryIn, index, xPosition, yPosition);
		}

		// if this function returns false, the player won't be able to insert the given item into this slot
		@Override
		public boolean isItemValid(ItemStack stack) {
			return GRTileEntityCellAnalyser.isItemValidForFuelSlot(stack);
		}
	}*/

	// SlotSmeltableInput is a slot for input items
	public class SlotSmeltableInput extends SlotItemHandler {
		public SlotSmeltableInput(IItemHandler inventoryIn, int index, int xPosition, int yPosition) {
			super(inventoryIn, index, xPosition, yPosition);
		}

		// if this function returns false, the player won't be able to insert the given item into this slot
		@Override
		public boolean isItemValid(ItemStack stack) {
			return (stack.getItem()==GRItems.OrganicMatter);
		}
	}

	// SlotOutput is a slot that will not accept any items
	public class SlotOutput extends SlotItemHandler {
		public SlotOutput(IItemHandler inventoryIn, int index, int xPosition, int yPosition) {
			super(inventoryIn, index, xPosition, yPosition);
		}

		// if this function returns false, the player won't be able to insert the given item into this slot
		@Override
		public boolean isItemValid(ItemStack stack) {
			return false;
		}
	}
}

 

 

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

So now I changed that and made the progress one actually do math for the progress of the item its "burning"

 

But now it shows energy in the GUI until I put an item in. The second it start processing the item both values go back to 0 and stay there till it is finished. Is there some kind of GUI make I could use for when I end up making my own? GUI's make me sad.

 

GUI code-http://pastebin.com/hZiiqzj8

 

Tile Entity Code-http://pastebin.com/UfyN1h2M

 

and container code just in case, I don't think  I changed anything here though

 

package com.theundertaker11.GeneticsReborn.blocks.cellanalyser;

import com.theundertaker11.GeneticsReborn.items.GRItems;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

/**
 * User: brandon3055
 * Date: 06/01/2015
 *
 * ContainerSmelting is used to link the client side gui to the server side inventory and it is where
 * you add the slots holding items. It is also used to send server side data such as progress bars to the client
 * for use in guis
 */
public class ContainerCellAnalyser extends Container {

	// Stores the tile entity instance for later use
	private GRTileEntityCellAnalyser tileInventory;

	// These store cache values, used by the server to only update the client side tile entity when values have changed
	private int [] cachedFields;

	// must assign a slot index to each of the slots used by the GUI.
	// For this container, we can see the furnace fuel, input, and output slots as well as the player inventory slots and the hotbar.
	// Each time we add a Slot to the container using addSlotToContainer(), it automatically increases the slotIndex, which means
	//  0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 
	//  9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
	//  36 - 39 = fuel slots (tileEntity 0 - 3)
	//  40 - 44 = input slots (tileEntity 4 - 
	//  45 - 49 = output slots (tileEntity 9 - 13)

	private final int HOTBAR_SLOT_COUNT = 9;
	private final int PLAYER_INVENTORY_ROW_COUNT = 3;
	private final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
	private final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
	private final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;

	//public final int FUEL_SLOTS_COUNT = 4;
	public final int INPUT_SLOTS_COUNT = 1;
	public final int OUTPUT_SLOTS_COUNT = 1;
	public final int TOTAL_SLOTS_COUNT = INPUT_SLOTS_COUNT + OUTPUT_SLOTS_COUNT;

	// slot index is the unique index for all slots in this container i.e. 0 - 35 for invPlayer then 36 - 49 for tileInventory
	private final int VANILLA_FIRST_SLOT_INDEX = 0;
	//private final int FIRST_FUEL_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
	private final int INPUT_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
	private final int OUTPUT_SLOT_INDEX = INPUT_SLOT_INDEX + INPUT_SLOTS_COUNT;

	// slot number is the slot number within each component; i.e. invPlayer slots 0 - 35, and tileInventory slots 0 - 14
	//private final int FIRST_FUEL_SLOT_NUMBER = 0;
	private final int INPUT_SLOT_NUMBER = 0;
	private final int OUTPUT_SLOT_NUMBER = 0;

	public ContainerCellAnalyser(InventoryPlayer invPlayer, GRTileEntityCellAnalyser tileInventory){
		this.tileInventory = tileInventory;

		final int SLOT_X_SPACING = 18;
		final int SLOT_Y_SPACING = 18;
		final int HOTBAR_XPOS = 8;
		final int HOTBAR_YPOS = 183;
		// Add the players hotbar to the gui - the [xpos, ypos] location of each item
		for (int x = 0; x < HOTBAR_SLOT_COUNT; x++) {
			int slotNumber = x;
			addSlotToContainer(new Slot(invPlayer, slotNumber, HOTBAR_XPOS + SLOT_X_SPACING * x, HOTBAR_YPOS));
		}

		final int PLAYER_INVENTORY_XPOS = 8;
		final int PLAYER_INVENTORY_YPOS = 125;
		// Add the rest of the players inventory to the gui
		for (int y = 0; y < PLAYER_INVENTORY_ROW_COUNT; y++) {
			for (int x = 0; x < PLAYER_INVENTORY_COLUMN_COUNT; x++) {
				int slotNumber = HOTBAR_SLOT_COUNT + y * PLAYER_INVENTORY_COLUMN_COUNT + x;
				int xpos = PLAYER_INVENTORY_XPOS + x * SLOT_X_SPACING;
				int ypos = PLAYER_INVENTORY_YPOS + y * SLOT_Y_SPACING;
				addSlotToContainer(new Slot(invPlayer, slotNumber,  xpos, ypos));
			}
		}
		/*
		final int FUEL_SLOTS_XPOS = 53;
		final int FUEL_SLOTS_YPOS = 96;
		// Add the tile fuel slots
		for (int x = 0; x < FUEL_SLOTS_COUNT; x++) {
			int slotNumber = x + FIRST_FUEL_SLOT_NUMBER;
			addSlotToContainer(new SlotFuel(tileInventory, slotNumber, FUEL_SLOTS_XPOS + SLOT_X_SPACING * x, FUEL_SLOTS_YPOS));
		}
		*/
		IItemHandler itemhandlerinput = tileInventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
		IItemHandler itemhandleroutput = tileInventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
		final int INPUT_SLOTS_XPOS = 26;
		final int INPUT_SLOTS_YPOS = 24;
		// Add the tile input slots
		for (int y = 0; y < INPUT_SLOTS_COUNT; y++) {
			int slotNumber = y + INPUT_SLOT_NUMBER;
			addSlotToContainer(new SlotSmeltableInput(itemhandlerinput, slotNumber, INPUT_SLOTS_XPOS, INPUT_SLOTS_YPOS+ SLOT_Y_SPACING * y));
		}

		final int OUTPUT_SLOTS_XPOS = 134;
		final int OUTPUT_SLOTS_YPOS = 24;
		// Add the tile output slots
		for (int y = 0; y < OUTPUT_SLOTS_COUNT; y++) {
			int slotNumber = y + OUTPUT_SLOT_NUMBER;
			addSlotToContainer(new SlotOutput(itemhandleroutput, slotNumber, OUTPUT_SLOTS_XPOS, OUTPUT_SLOTS_YPOS + SLOT_Y_SPACING * y));
		}
	}

	// Checks each tick to make sure the player is still able to access the inventory and if not closes the gui
	@Override
	public boolean canInteractWith(EntityPlayer player)
	{
		return tileInventory.isUseableByPlayer(player);
	}

	// This is where you specify what happens when a player shift clicks a slot in the gui
	//  (when you shift click a slot in the TileEntity Inventory, it moves it to the first available position in the hotbar and/or
	//    player inventory.  When you you shift-click a hotbar or player inventory item, it moves it to the first available
	//    position in the TileEntity inventory - either input or fuel as appropriate for the item you clicked)
	// At the very least you must override this and return null or the game will crash when the player shift clicks a slot
	// returns null if the source slot is empty, or if none of the source slot items could be moved.
	//   otherwise, returns a copy of the source stack
	@Override
	public ItemStack transferStackInSlot(EntityPlayer player, int sourceSlotIndex)
	{
		ItemStack itemstack = null;
        Slot slot = this.inventorySlots.get(sourceSlotIndex);

        if (slot != null && slot.getHasStack()) {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (sourceSlotIndex < GRTileEntityCellAnalyser.getSIZE()) {
                if (!this.mergeItemStack(itemstack1, GRTileEntityCellAnalyser.getSIZE(), this.inventorySlots.size(), true)) {
                    return null;
                }
            }else if (!this.mergeItemStack(itemstack1, 0, GRTileEntityCellAnalyser.getSIZE(), false)) {
                return null;
            }

            if (itemstack1.stackSize == 0) {
                slot.putStack(null);
            } else {
                slot.onSlotChanged();
            }
        }
        return itemstack;
		/*
		Slot sourceSlot = (Slot)inventorySlots.get(sourceSlotIndex);
		if (sourceSlot == null || !sourceSlot.getHasStack()) return null;
		ItemStack sourceStack = sourceSlot.getStack();
		ItemStack copyOfSourceStack = sourceStack.copy();

		// Check if the slot clicked is one of the vanilla container slots
		if (sourceSlotIndex >= VANILLA_FIRST_SLOT_INDEX && sourceSlotIndex < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
			// This is a vanilla container slot so merge the stack into one of the furnace slots
			// If the stack is smeltable try to merge merge the stack into the input slots
			if (GRTileEntityCellAnalyser.getSmeltingResultForItem(sourceStack) != null){
				if (!mergeItemStack(sourceStack, FIRST_INPUT_SLOT_INDEX, FIRST_INPUT_SLOT_INDEX + INPUT_SLOTS_COUNT, false)){
					return null;
				}
			}	else if (GRTileEntityCellAnalyser.getItemBurnTime(sourceStack) > 0) {
				if (!mergeItemStack(sourceStack, FIRST_FUEL_SLOT_INDEX, FIRST_FUEL_SLOT_INDEX + FUEL_SLOTS_COUNT, true)) {
					// Setting the boolean to true places the stack in the bottom slot first
					return null;
				}
			}	else {
				return null;
			}
		} else if (sourceSlotIndex >= FIRST_FUEL_SLOT_INDEX && sourceSlotIndex < FIRST_FUEL_SLOT_INDEX + FURNACE_SLOTS_COUNT) {
			// This is a furnace slot so merge the stack into the players inventory: try the hotbar first and then the main inventory
			//   because the main inventory slots are immediately after the hotbar slots, we can just merge with a single call
			if (!mergeItemStack(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) {
				return null;
			}
		} else {
			System.err.print("Invalid slotIndex:" + sourceSlotIndex);
			return null;
		}

		// If stack size == 0 (the entire stack was moved) set slot contents to null
		if (sourceStack.stackSize == 0) {
			sourceSlot.putStack(null);
		} else {
			sourceSlot.onSlotChanged();
		}

		sourceSlot.onPickupFromSlot(player, sourceStack);
		return copyOfSourceStack;
		*/
	}

	/* Client Synchronization */

	// This is where you check if any values have changed and if so send an update to any clients accessing this container
	// The container itemstacks are tested in Container.detectAndSendChanges, so we don't need to do that
	// We iterate through all of the TileEntity Fields to find any which have changed, and send them.
	// You don't have to use fields if you don't wish to; just manually match the ID in sendProgressBarUpdate with the value in
	//   updateProgressBar()
	// The progress bar values are restricted to shorts.  If you have a larger value (eg int), it's not a good idea to try and split it
	//   up into two shorts because the progress bar values are sent independently, and unless you add synchronisation logic at the
	//   receiving side, your int value will be wrong until the second short arrives.  Use a custom packet instead.
	@Override
	public void detectAndSendChanges() {
		super.detectAndSendChanges();

		boolean allFieldsHaveChanged = false;
		boolean fieldHasChanged [] = new boolean[tileInventory.getFieldCount()];
		if (cachedFields == null) {
			cachedFields = new int[tileInventory.getFieldCount()];
			allFieldsHaveChanged = true;
		}
		for (int i = 0; i < cachedFields.length; ++i) {
			if (allFieldsHaveChanged || cachedFields[i] != tileInventory.getField(i)) {
				cachedFields[i] = tileInventory.getField(i);
				fieldHasChanged[i] = true;
			}
		}

	// go through the list of listeners (players using this container) and update them if necessary
    for (IContainerListener listener : this.listeners) {
			for (int fieldID = 0; fieldID < tileInventory.getFieldCount(); ++fieldID) {
				if (fieldHasChanged[fieldID])
				{
					// Note that although sendProgressBarUpdate takes 2 ints on a server these are truncated to shorts
					listener.sendProgressBarUpdate(this, fieldID, cachedFields[fieldID]);
				}
			}
		}
	}

	// Called when a progress bar update is received from the server. The two values (id and data) are the same two
	// values given to sendProgressBarUpdate.  In this case we are using fields so we just pass them to the tileEntity.
	@SideOnly(Side.CLIENT)
	@Override
	public void updateProgressBar(int id, int data) {
		tileInventory.setField(id, data);
	}

	// SlotFuel is a slot for fuel items
	/*public class SlotFuel extends Slot {
		public SlotFuel(IInventory inventoryIn, int index, int xPosition, int yPosition) {
			super(inventoryIn, index, xPosition, yPosition);
		}

		// if this function returns false, the player won't be able to insert the given item into this slot
		@Override
		public boolean isItemValid(ItemStack stack) {
			return GRTileEntityCellAnalyser.isItemValidForFuelSlot(stack);
		}
	}*/

	// SlotSmeltableInput is a slot for input items
	public class SlotSmeltableInput extends SlotItemHandler {
		public SlotSmeltableInput(IItemHandler inventoryIn, int index, int xPosition, int yPosition) {
			super(inventoryIn, index, xPosition, yPosition);
		}

		// if this function returns false, the player won't be able to insert the given item into this slot
		@Override
		public boolean isItemValid(ItemStack stack) {
			return (stack.getItem()==GRItems.OrganicMatter);
		}
	}

	// SlotOutput is a slot that will not accept any items
	public class SlotOutput extends SlotItemHandler {
		public SlotOutput(IItemHandler inventoryIn, int index, int xPosition, int yPosition) {
			super(inventoryIn, index, xPosition, yPosition);
		}

		// if this function returns false, the player won't be able to insert the given item into this slot
		@Override
		public boolean isItemValid(ItemStack stack) {
			return false;
		}
	}
}

 

Could you show me what you mean in a video or gif? And...

Is there some kind of GUI make I could use for when I end up making my own? GUI's make me sad.

What?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

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

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Sorry I had to type all that super fast, lot of things going on in the house right now. I see now I had a lot of typos. I made a video but its like 30 seconds long and my upload is trash so I'll post a link to it in a bit.

Also, I meant I want something that I can use to create GUI's instead of just trying to make the code. I am terrible at this type of stuff. I can't even make good looking textures from scratch, much less a whole GUI.

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

Sorry I had to type all that super fast, lot of things going on in the house right now. I see now I had a lot of typos. I made a video but its like 30 seconds long and my upload is trash so I'll post a link to it in a bit.

Also, I meant I want something that I can use to create GUI's instead of just trying to make the code. I am terrible at this type of stuff. I can't even make good looking textures from scratch, much less a whole GUI.

Not as in depth as you want for this one assuming you mean the code.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

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

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I figured as much. Finally finished uploading, here is the link

https://www.dropbox.com/s/qy1egavxrukq7d6/20161231_133149.rar?dl=0

Remove any part that removes energy and tell me what happens.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

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

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I'm glad you pointed that out, cause now I see I had a line that said

this.energy = (20*this.overclockers)

Which means as soon as operation started the energy was set to 20, and since it used that right away it just stayed at 0. (I went through and removed the overclocker things for now since they were ill thought out and messed things up.)

 

When I removed that the energy went down as it should, but the progress bar still always says 0%, as well as the fire emblem only glowing when there is full power. I don't know how to work with GUI's well enough to even know how I'm supposed to make the fire emblems height represent how much power is stored in the machine.

 

So to sum it up, the power shows how much RF is in there right when you mouse over, but the animation is only an on/off thing, and the progress bar still doesn't work at all.

[EDIT] Change that, the gui only removes 20 rf/t. Even if I'm giving it enough power from a bank, the GUI will still be taking away that much RF/t and won't update how much it actually has until you close and open it.

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

I'm glad you pointed that out, cause now I see I had a line that said

this.energy = (20*this.overclockers)

Which means as soon as operation started the energy was set to 20, and since it used that right away it just stayed at 0. (I went through and removed the overclocker things for now since they were ill thought out and messed things up.)

 

When I removed that the energy went down as it should, but the progress bar still always says 0%, as well as the fire emblem only glowing when there is full power. I don't know how to work with GUI's well enough to even know how I'm supposed to make the fire emblems height represent how much power is stored in the machine.

 

So to sum it up, the power shows how much RF is in there right when you mouse over, but the animation is only an on/off thing, and the progress bar still doesn't work at all.

[EDIT] Change that, the gui only removes 20 rf/t. Even if I'm giving it enough power from a bank, the GUI will still be taking away that much RF/t and won't update how much it actually has until you close and open it.

Put a println in Container#updateProgressBar so that it prints id and data.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

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

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Okay so that told me its updating the GUI to what the energyUsed(Current energy put into the item so far) is, but it never sends what the energy stored is. Console only prints ID 1 when I open it, and isn't sending ID 1 while it processes an item.

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

Okay so that told me its updating the GUI to what the energyUsed(Current energy put into the item so far) is, but it never sends what the energy stored is. Console only prints ID 1 when I open it, and isn't sending ID 1 while it processes an item.

Two possibilities I see

[*]energyUsed isn't changing at all (not likely)

[*]Or your if checking in detectAndSendChanges is not working (correctly).

To fix this since you don't have that many variables to work with you can manually do it, look at ContainerFurnace#detectAndSendChanges for an example of manual.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

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

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Alright that is true, I can check if each variable is different one at a time, since there is only like 2 I'm checking.

 

And energyUsed is updating, since in the console showed it going up at 20 rf/t like it should have.

I'll go and set them to manually check then come back here.

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

Okay so update, I went and made it manually do each variable, and it sends both if even one is different than before. My problems are still this

1) The fire animation only has 2 states, fully on or not at all. It's fully on if the power is 100% full and any other time(power<full) it is completely off.

2) Progress is still always 0%, but I've found something that might be the cause. So when I put print screens as such in the lines below,

public double percComplete()
{
	System.out.println("EnergyUsed:"+this.energyUsed+" EnergyNeeded:"+this.ENERGY_NEEDED);
	System.out.println("The number it is spitting out is"+(double)(this.energyUsed/this.ENERGY_NEEDED));
	return (double)(this.energyUsed/this.ENERGY_NEEDED);
}

I get this out in console (Note the EnergyUsed changed every tick, I just gave one example of what was printing out)

 

[19:29:02] [Client thread/INFO] [sTDOUT]: [com.theundertaker11.GeneticsReborn.blocks.cellanalyser.GRTileEntityCellAnalyser:percComplete:149]: EnergyUsed:2400 EnergyNeeded:5000

[19:29:02] [Client thread/INFO] [sTDOUT]: [com.theundertaker11.GeneticsReborn.blocks.cellanalyser.GRTileEntityCellAnalyser:percComplete:150]: The number it is spitting out is0.0

 

Is there something obvious I'm missing here or what?

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

While at work today I thought to myself "Oh my god I didn't set the 2 numbers to doubles, only the resulting int." So I did that and the progress bar works perfect, and shows the animation. I'm setting this thread as resolved.(Fire don't work but I'll try and figure that out myself now.)

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

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.