Jump to content

Recommended Posts

Posted (edited)

I have a problem with my custom GUI...

I made a Cuttingboard for my mod.

But there is one Problem. Ihe Items will appear in the slot but when I remove these with a right or left click it creates only a few items, the other seem to disappear...

 

Here are my three classes (Attachment was removed): ContainerKitchenboard.java is the container-class for the GUI...

                                              GuiKitchenboard.java is the gui-class for the GUI...

                                              CutManager.java will add items in the slots of the container...

 

Thanks for help!

 

 

 

Edited by VirtCraft
Removed outdated attachments and corrected that horrible english!
Posted

It means that you didn't set the item in the slot on the server. 

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.

Posted

Please post your code so it can be read online - either in spoilers (eye icon) and code tags (<> icon) on this forum, or on a site like pastebin, or ideally as a full github repository.

Posted
Spoiler

package net.virtcraft.farmingplus.gui.kitchenboard;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.virtcraft.farmingplus.blocks.RegisterBlocks;
import net.virtcraft.farmingplus.items.RegisterItems;
import net.virtcraft.farmingplus.utils.reference.CutItemBundle;
import net.virtcraft.farmingplus.utils.reference.InventoryBundle;

public class ContainerKitchenboard extends Container{
	
	private final World worldObj;
    private final BlockPos pos;
    public InventoryCrafting cutInput = new InventoryCrafting(this, 1, 1);
    public InventoryCraftResult cutOutput = new InventoryCraftResult();
    public static InventoryBundle Inventorys = new InventoryBundle();


	
	public ContainerKitchenboard(InventoryPlayer playerInventory, World worldIn, BlockPos posIn) {
		
		this.worldObj = worldIn;
		this.pos = posIn;
		Inventorys.setPlayerInventory(playerInventory);
		
		this.addSlotToContainer(new Slot(cutOutput, 0, 124, 35));
		
            
        this.addSlotToContainer(new Slot(this.cutInput, 0, 48, 35));
            
		
		for (int k = 0; k < 3; ++k)
        {
            for (int i1 = 0; i1 < 9; ++i1)
            {
                this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
            }
        }
		
		for (int l = 0; l < 9; ++l)
        {
            this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
        }

        this.onCraftMatrixChanged(this.cutInput);
    }
    
    


	@Override
	public boolean canInteractWith(EntityPlayer playerIn) {
		
        return playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
	}
	

	@Override
	public void onCraftMatrixChanged(IInventory inventoryIn) {
		
		Inventorys.setInputInventory(cutInput);
		Inventorys.setOutputInventory(cutOutput);


		CutManager.Cut(Inventorys);

		super.onCraftMatrixChanged(inventoryIn);
	}

	@Override
	public void onContainerClosed(EntityPlayer playerIn) {
		CutManager.print = false;
		super.onContainerClosed(playerIn);
	}
}

 

^ My ContainerClass

 

Spoiler

package net.virtcraft.farmingplus.gui.kitchenboard;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerWorkbench;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class GuiKitchenboard extends GuiContainer{
	
    private static final ResourceLocation Recource = new ResourceLocation("farmingplus:textures/gui/container/KitchenBoardGui.png");

    public GuiKitchenboard(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition)
    {
        super(new ContainerKitchenboard(playerInv, worldIn, blockPosition));
    }

    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
    {
        this.fontRendererObj.drawString("Cut", 27, 40, 4210752);
        this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
    }

	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
    {
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(Recource);
        int i = (this.width - this.xSize) / 2;
        int j = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
    }


}

 

^ My GuiClass

 

Spoiler

package net.virtcraft.farmingplus.gui.kitchenboard;

import jdk.internal.util.xml.impl.Input;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.virtcraft.farmingplus.utils.reference.CutItemBundle;
import net.virtcraft.farmingplus.utils.reference.InventoryBundle;
import org.lwjgl.Sys;

public class CutManager {
	
	static int RecipeAmount = 0;
	static int run = 0;
	static Item[] InputList = new Item[1000];
	static Item[] OutputList = new Item[1000];
	static int[] AmountList = new int[1000];
	static int LoopAmount = 0;
	static boolean print = false;
	static int TickCount = 0;

	
	
	public static void Cut(InventoryBundle Inventorys){

		LoopAmount = RecipeAmount;

		while(LoopAmount <= RecipeAmount && LoopAmount >= 0){

			if(Inventorys.getInputInventory().getStackInSlot(0) != null){

				System.out.println(Inventorys.getInputInventory().getStackInSlot(0).getItem());

				if(Inventorys.getInputInventory().getStackInSlot(0).getItem() == InputList[LoopAmount]) {
					cutItems(Inventorys, new CutItemBundle(InputList[LoopAmount], OutputList[LoopAmount], AmountList[LoopAmount]));

				}
			}
			LoopAmount--;
		}
	}

	/** Add a cut for the KitchenBoard. */
	public static void addCut(Item Input, Item Output, int amount){

		if(run != 1000){

			InputList[run] = Input;
			OutputList[run] = Output;
			AmountList[run] = amount;

			RecipeAmount++;
			run++;
		}
		else{
			
			System.out.println("Some Cutrecipes would be not registered...");
			System.out.println("Reason: The limit of 1000 Cutrecipes is used");
			
		}
		
		
	}

	static CutItemBundle ItemsToCut;
	static InventoryBundle InventorysToCut;

	public static void cutItems(InventoryBundle guiInventory, CutItemBundle originalItems){
		if(guiInventory.getOutputInventory().getStackInSlot(0) == null){
			addFist(guiInventory, originalItems);
			print = true;
			ItemsToCut = originalItems;
			InventorysToCut = guiInventory;
		}
		else {
			if (guiInventory.getOutputInventory().getStackInSlot(0).stackSize != 64) {
				if (guiInventory.getOutputInventory().getStackInSlot(0).getItem() == originalItems.getOutputItem()) {
					print = true;
					ItemsToCut = originalItems;
					InventorysToCut = guiInventory;
				}
			}
		}
	}

	public static void setCutItems(InventoryBundle inventorys, CutItemBundle items){

		if(inventorys.getOutputInventory().getStackInSlot(0) != null && inventorys.getInputInventory().getStackInSlot(0) != null) {
			if (inventorys.getInputInventory().getStackInSlot(0).stackSize != 0 &&
					inventorys.getInputInventory().getStackInSlot(0).getItem() == items.getInputItem() &&
					inventorys.getOutputInventory().getStackInSlot(0).stackSize != items.getOutputItem().getItemStackLimit() &&
					inventorys.getOutputInventory().getStackInSlot(0).getItem() == items.getOutputItem()) {



				inventorys.getInputInventory().getStackInSlot(0).stackSize--;
				inventorys.getOutputInventory().getStackInSlot(0).stackSize = inventorys.getOutputInventory().getStackInSlot(0).stackSize + items.getOutputAmount();


			}

			else{
				System.out.print("false");
				print = false;

			}

		}
		else{
			if(inventorys.getOutputInventory().getStackInSlot(0) == null && inventorys.getInputInventory().getStackInSlot(0) != null){
				if(inventorys.getInputInventory().getStackInSlot(0).getItem() == items.getInputItem()){
					addFist(inventorys, items);
					setCutItems(inventorys, items);
				}
				else{
					System.out.print("false");

					print = false;

				}

			}
			else{
				System.out.print("false");

				print = false;
			}

		}

	}

	public static void addFist(InventoryBundle invs, CutItemBundle items){
		invs.getOutputInventory().setInventorySlotContents(0, items.getOutputItemStack());
		invs.getInputInventory().getStackInSlot(0).stackSize--;
	}

	public static void countTicksForKitchenboard(){
		TickCount++;

		if(TickCount == 20){
			TickCount = 0;
			if(print) setCutItems(InventorysToCut, ItemsToCut);
		}


	}
}

 

 

^ My Manager-Class (This class adds the Items in the slots)

 

Thanks for Help!

Posted (edited)

Here I call the method "Cut" from the CutManager in the Container-Class:

Spoiler

	@Override
	public void onCraftMatrixChanged(IInventory inventoryIn) {
		
		Inventorys.setInputInventory(cutInput);
		Inventorys.setOutputInventory(cutOutput);


		CutManager.Cut(Inventorys);

		super.onCraftMatrixChanged(inventoryIn);
	}

 

Here I call the method "CountTicksForKitchenboard" in my Events-Class:

Spoiler

@SubscribeEvent
    public void tickEvent(TickEvent.WorldTickEvent event){
        CutManager.countTicksForKitchenboard();

    }

 

And here I call the "addCut" method in my Main-Class (for adding a Cut to the list) and register the Events-Class and the GuiHandler

Spoiler

public void Init(FMLInitializationEvent event){
		//This is the InitialisationEvent
		
		CutManager.addCut(Items.APPLE, Items.CAKE, 1); //Some random Items for testing
		CutManager.addCut(Items.BEEF, Items.APPLE, 1);

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

		MinecraftForge.EVENT_BUS.register(new Events());
	}

 

Here I open the Container in a Block:

Spoiler

@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
		
		playerIn.openGui(Main.instance, GuiHandler.KitchenBoardID, worldIn, pos.getX(), pos.getY(), pos.getZ());
		
		return super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);
	}

 

And there is my GuiHandler:

Spoiler

package net.virtcraft.farmingplus.gui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
import net.virtcraft.farmingplus.gui.kitchenboard.ContainerKitchenboard;
import net.virtcraft.farmingplus.gui.kitchenboard.GuiKitchenboard;

public class GuiHandler implements IGuiHandler{
	
	public static final int KitchenBoardID = 1;
	
	@Override
	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		switch(ID){
		case KitchenBoardID:	return new ContainerKitchenboard(player.inventory, world, new BlockPos(x, y, z));
		}
		return null;
	}

	@Override
	public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		switch(ID){
		case KitchenBoardID:	return new GuiKitchenboard(player.inventory, world, new BlockPos(x, y, z));
		}
		return null;
		
	}

}

 

 

Thanks for Help

Edited by VirtCraft

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.