Jump to content

[1.9] [SOLVED] GUI issue


GlowingWater

Recommended Posts

When I put an item to my container, it automatically copies into the hotbar. What causes this?

 

Container Class

package com.gwater.decorationmod.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

import com.gwater.decorationmod.tileentity.TileEntityCrate;

public class ContainerCrate extends Container {

private TileEntityCrate tileEntityCrate;

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;

private final int VANILLA_FIRST_SLOT_INDEX = 0;
private final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
private final int TE_INVENTORY_ROW_COUNT = 3;
private final int TE_INVENTORY_COLUMN_COUNT = 3;
private final int TE_INVENTORY_SLOT_COUNT = 3;

public ContainerCrate(InventoryPlayer invPlayer, TileEntityCrate tileEntityCrate) {
	this.tileEntityCrate = tileEntityCrate;
	final int SLOT_X_SPACING = 18;
	final int SLOT_Y_SPACING = 18;
	final int HOTBAR_XPOS = 8;
	final int HOTBAR_YPOS = 140;

	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 = 82;

	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));
		}
	}

	if(TE_INVENTORY_SLOT_COUNT != tileEntityCrate.getSizeInventory()) {
		System.err.println("Mismatched slot count in ContainerCrate(" + TE_INVENTORY_SLOT_COUNT + ") and TileEntityCrate(" + tileEntityCrate.getSizeInventory() + ")");
	}

	final int TE_INVENTORY_XPOS = 62;
	final int TE_INVENTORY_YPOS = 15;

	for(int y = 0; y < TE_INVENTORY_ROW_COUNT; y++) {
		for(int x = 0; x < TE_INVENTORY_COLUMN_COUNT; x++) {
			int slotNumber = TE_INVENTORY_SLOT_COUNT + y * TE_INVENTORY_COLUMN_COUNT + x;
			int xpos = TE_INVENTORY_XPOS + SLOT_X_SPACING * x;
			int ypos = TE_INVENTORY_YPOS + SLOT_Y_SPACING * y;
			addSlotToContainer(new Slot(invPlayer, slotNumber, xpos, ypos));
		}
	}
		//addSlotToContainer(new Slot(tileEntityCrate, slotNumber, TILE_INVENTORY_XPOS + SLOT_X_SPACING * x, TILE_INVENTORY_YPOS3));
}

@Override
public boolean canInteractWith(EntityPlayer playerIn) {
	return tileEntityCrate.isUseableByPlayer(playerIn);
}

@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int sourceSlotIndex) {
	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 the tile inventory
		if (!mergeItemStack(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT, false)){
			return null;
		}
	} else if (sourceSlotIndex >= TE_INVENTORY_FIRST_SLOT_INDEX && sourceSlotIndex < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) {
		// This is a TE slot so merge the stack into the players inventory
		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(playerIn, sourceStack);
	return copyOfSourceStack;
}

@Override
public void onContainerClosed(EntityPlayer playerIn) {
	super.onContainerClosed(playerIn);
	this.tileEntityCrate.closeInventory(playerIn);
}
}

 

EDIT

 

turned:

for(int y = 0; y < TE_INVENTORY_ROW_COUNT; y++) {
		for(int x = 0; x < TE_INVENTORY_COLUMN_COUNT; x++) {
			int slotNumber = TE_INVENTORY_ROW_COUNT + y * TE_INVENTORY_COLUMN_COUNT + x; //3 + 0 * 3 + 0;
			int xpos = TE_INVENTORY_XPOS + x * SLOT_X_SPACING;
			int ypos = TE_INVENTORY_YPOS + y * SLOT_Y_SPACING;
			addSlotToContainer(new Slot(invPlayer, slotNumber, xpos, ypos));
		}
	}

 

to:

for(int y = 0; y < TE_INVENTORY_ROW_COUNT; y++) {
		for(int x = 0; x < TE_INVENTORY_COLUMN_COUNT; x++) {
			int slotNumber = TE_INVENTORY_ROW_COUNT + y * TE_INVENTORY_COLUMN_COUNT + x; //3 + 0 * 3 + 0;
			int xpos = TE_INVENTORY_XPOS + x * SLOT_X_SPACING;
			int ypos = TE_INVENTORY_YPOS + y * SLOT_Y_SPACING;
			addSlotToContainer(new Slot(tileEntityCrate, slotNumber, xpos, ypos));
		}
	}

 

and console log appears when right-click the entity:

[20:02:19] [pool-2-thread-1/WARN]: Couldn't look up profile properties for com.mojang.authlib.GameProfile@179586f[id=45c2c1e2-9dd4-3d62-8e53-82e2b4b32b4a,name=Player843,properties={},legacy=false]
com.mojang.authlib.exceptions.AuthenticationException: The client has sent too many requests within a certain amount of time
at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:65) ~[YggdrasilAuthenticationService.class:?]
at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService.fillGameProfile(YggdrasilMinecraftSessionService.java:175) [YggdrasilMinecraftSessionService.class:?]
at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService$1.load(YggdrasilMinecraftSessionService.java:59) [YggdrasilMinecraftSessionService$1.class:?]
at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService$1.load(YggdrasilMinecraftSessionService.java:56) [YggdrasilMinecraftSessionService$1.class:?]
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524) [guava-17.0.jar:?]
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317) [guava-17.0.jar:?]
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280) [guava-17.0.jar:?]
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195) [guava-17.0.jar:?]
at com.google.common.cache.LocalCache.get(LocalCache.java:3934) [guava-17.0.jar:?]
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938) [guava-17.0.jar:?]
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821) [guava-17.0.jar:?]
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4827) [guava-17.0.jar:?]
at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService.fillProfileProperties(YggdrasilMinecraftSessionService.java:165) [YggdrasilMinecraftSessionService.class:?]
at net.minecraft.client.Minecraft.getProfileProperties(Minecraft.java:3038) [Minecraft.class:?]
at net.minecraft.client.resources.SkinManager$3.run(SkinManager.java:130) [skinManager$3.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_77]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_77]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_77]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_77]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]
[20:02:33] [server thread/INFO] [sTDERR]: [com.gwater.decorationmod.container.ContainerCrate:<init>:52]: Mismatched slot count in ContainerCrate(3) and TileEntityCrate(9)
[20:02:33] [server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: 9
at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_77]
at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_77]
at net.minecraft.util.Util.runTask(Util.java:24) [util.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:738) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:683) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:155) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:532) [MinecraftServer.class:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 9
at com.gwater.decorationmod.tileentity.TileEntityCrate.getStackInSlot(TileEntityCrate.java:26) ~[TileEntityCrate.class:?]
at net.minecraft.inventory.Slot.getStack(Slot.java:81) ~[slot.class:?]
at net.minecraft.inventory.Container.getInventory(Container.java:62) ~[Container.class:?]
at net.minecraft.inventory.Container.onCraftGuiOpened(Container.java:51) ~[Container.class:?]
at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:93) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2694) ~[EntityPlayer.class:?]
at com.gwater.decorationmod.block.Crate.onBlockActivated(Crate.java:42) ~[Crate.class:?]
at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:455) ~[PlayerInteractionManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processRightClickBlock(NetHandlerPlayServer.java:706) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:68) ~[CPacketPlayerTryUseItem.class:?]
at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:13) ~[CPacketPlayerTryUseItem.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_77]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_77]
at net.minecraft.util.Util.runTask(Util.java:23) ~[util.class:?]
... 5 more
[20:02:33] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking player
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:785) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:683) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:155) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:532) [MinecraftServer.class:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 9
at com.gwater.decorationmod.tileentity.TileEntityCrate.getStackInSlot(TileEntityCrate.java:26) ~[TileEntityCrate.class:?]
at net.minecraft.inventory.Slot.getStack(Slot.java:81) ~[slot.class:?]
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:84) ~[Container.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:290) ~[EntityPlayerMP.class:?]
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2086) ~[World.class:?]
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:864) ~[WorldServer.class:?]
at net.minecraft.world.World.updateEntity(World.java:2051) ~[World.class:?]
at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:666) ~[WorldServer.class:?]
at net.minecraft.world.World.updateEntities(World.java:1858) ~[World.class:?]
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:637) ~[WorldServer.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:779) ~[MinecraftServer.class:?]
... 4 more
[20:02:33] [server thread/ERROR]: This crash report has been saved to: C:\Users\El3mentz\Desktop\DecorationMod\run\.\crash-reports\crash-2016-04-13_20.02.33-server.txt
[20:02:33] [server thread/INFO]: Stopping server
[20:02:33] [server thread/INFO]: Saving players
[20:02:33] [server thread/INFO]: Saving worlds
[20:02:33] [server thread/INFO]: Saving chunks for level 'Showcase'/Overworld
[20:02:33] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:645]: ---- Minecraft Crash Report ----
// You should try our sister game, Minceraft!

Time: 13.04.16 20:02
Description: Ticking player

java.lang.ArrayIndexOutOfBoundsException: 9
at com.gwater.decorationmod.tileentity.TileEntityCrate.getStackInSlot(TileEntityCrate.java:26)
at net.minecraft.inventory.Slot.getStack(Slot.java:81)
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:84)
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:290)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2086)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:864)
at net.minecraft.world.World.updateEntity(World.java:2051)
at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:666)
at net.minecraft.world.World.updateEntities(World.java:1858)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:637)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:779)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:683)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:155)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:532)
at java.lang.Thread.run(Thread.java:745)

 

Found the important logs. Maybe it will help:

at com.gwater.decorationmod.tileentity.TileEntityCrate.getStackInSlot(TileEntityCrate.java:26) ~[TileEntityCrate.class:?]
at com.gwater.decorationmod.block.Crate.onBlockActivated(Crate.java:42) ~[Crate.class:?]

 

Fixed it. I had to change this line of code:

int slotNumber = TE_INVENTORY_ROW_COUNT + y * TE_INVENTORY_COLUMN_COUNT + x;

 

to:

int slotNumber = x + y * 3; //position + position * slotAmount

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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