public class ContainerSpiceFurnace extends Container
{
public IInventory furnace;
public ContainerSpiceFurnace(EntityPlayer player ,TileEntitySpiceFurnace furnace)
{
this.addSlotToContainer(new Slot(this.furnace));
}
}
That is not the correct "Container" class - you want the Minecraft container, not Java's. Remove all your imports, then, if you are in Eclipse, press ctrl-shift-o to reimport and they should be fixed; otherwise, remove the imports and add them manually.
the etc.packetpipeline.sendtoserver line comes up with an error.
public void sendToServer(AbstractPacket message) { this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); this.channels.get(Side.CLIENT).writeAndFlush(message);}
both lines are reported in the errorI'm willing to bet more needs to be shown. Either way, im unsure what to trace it back to. This is my first time dealing with this stuff and learning it
the etc.packetpipeline.sendtoserver line comes up with an error.
public void sendToServer(AbstractPacket message) { this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); this.channels.get(Side.CLIENT).writeAndFlush(message);}
both lines are reported in the errorI'm willing to bet more needs to be shown. Either way, im unsure what to trace it back to. This is my first time dealing with this stuff and learning it
You need to post what the errors say or it's pretty difficult to help. There shouldn't be any errors in the PacketPipeline class (and you actually probably shouldn't be using that now, but that's a post for another day). Double-check your imports, make sure you registered your packet, and if that doesn't help, post your the error text.
You need to post what the errors say or it's pretty difficult to help. There shouldn't be any errors in the PacketPipeline class (and you actually probably shouldn't be using that now, but that's a post for another day). Double-check your imports, make sure you registered your packet, and if that doesn't help, post your the error text.
hm, I missed registering pipeline in the load (post init was covered). and now the game won't crash but it has a fatal error.
[22:59:07] [Server thread/ERROR] [FML]: There was a critical exception handling a packet on channel TUT
io.netty.handler.codec.DecoderException: java.lang.NullPointerException
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:80) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:232) [NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:716) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [IntegratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742) [MinecraftServer$2.class:?]
Caused by: java.lang.NullPointerException
at com.maplestory.etc.lib.ProxyCommon.getServerGuiElement(ProxyCommon.java:119) ~[ProxyCommon.class:?]
at cpw.mods.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:241) ~[NetworkRegistry.class:?]
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:75) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2510) ~[EntityPlayer.class:?]
at com.maplestory.etc.keys.OpenGuiPacket.handleServerSide(OpenGuiPacket.java:44) ~[OpenGuiPacket.class:?]
at com.maplestory.etc.keys.PacketPipeline.decode(PacketPipeline.java:106) ~[PacketPipeline.class:?]
at com.maplestory.etc.keys.PacketPipeline.decode(PacketPipeline.java:1) ~[PacketPipeline.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?]
... 13 more
hm, I missed registering pipeline in the load (post init was covered). and now the game won't crash but it has a fatal error.
Caused by: java.lang.NullPointerException
at com.maplestory.etc.lib.ProxyCommon.getServerGuiElement(ProxyCommon.java:119) ~[ProxyCommon.class:?]
Null pointer exception at line 119 in your common proxy; that means your open GUI packet went through, but you're missing something when you try to open the GUI. Make sure you return a valid Container for your server element, just as you do a valid Gui for the client element.
Null pointer exception at line 119 in your common proxy; that means your open GUI packet went through, but you're missing something when you try to open the GUI. Make sure you return a valid Container for your server element, just as you do a valid Gui for the client element.
hm. I have it as
if (guiId == Etc.GUI_EQUIP)
{
return new Container_Equip_Inventory(player, player.inventory, ExtendedPlayer.get(player).inventory);
}
and I tried replacing the container file with your exact coding to see if it'd work, adjusting it to fit what I have and it's still erroring here. The error log menions gui and container. could the gui be the problem or is it for sure the container
if (guiId == Etc.GUI_EQUIP)
{
return new Container_Equip_Inventory(player, player.inventory, ExtendedPlayer.get(player).inventory);
}
and I tried replacing the container file with your exact coding to see if it'd work, adjusting it to fit what I have and it's still erroring here. The error log menions gui and container. could the gui be the problem or is it for sure the container
Is that line 119? Is your extended properties class named "ExtendedPlayer"? Is there a field named "inventory" in your extended properties, and did you initialize that field to a non-null value?
Is that line 119? Is your extended properties class named "ExtendedPlayer"? Is there a field named "inventory" in your extended properties, and did you initialize that field to a non-null value?
yes the return is 119. my extendedplayer is as follows
package com.maplestory.etc.keys;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import com.maplestory.etc.Etc;
import com.maplestory.etc.inventory.Inventory_Equip_Inventory;
import com.maplestory.etc.lib.ProxyCommon;
public class ExtendedPlayer implements IExtendedEntityProperties
{
public final static String EXT_PROP_NAME = "ExtendedPlayer";
private final EntityPlayer player;
public final Inventory_Equip_Inventory inventory = new Inventory_Equip_Inventory();
public ExtendedPlayer(EntityPlayer player) {
this.player = player;
}
public static final void register(EntityPlayer player) {
player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player));
}
public static final ExtendedPlayer get(EntityPlayer player) {
return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);
}
@Override
public final void saveNBTData(NBTTagCompound compound) {
NBTTagCompound properties = new NBTTagCompound();
inventory.writeToNBT(properties);
compound.setTag(EXT_PROP_NAME, properties);
}
@Override
public final void loadNBTData(NBTTagCompound compound) {
NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
inventory.readFromNBT(properties);
}
@Override
public void init(Entity entity, World world) {}
public void onUpdate() {
}
private static final String getSaveKey(EntityPlayer player) {
return player.getCommandSenderName() + ":" + EXT_PROP_NAME;
}
public static final void saveProxyData(EntityPlayer player) {
NBTTagCompound savedData = new NBTTagCompound();
ExtendedPlayer.get(player).saveNBTData(savedData);
ProxyCommon.storeEntityData(getSaveKey(player), savedData);
}
public static final void loadProxyData(EntityPlayer player) {
ExtendedPlayer playerData = ExtendedPlayer.get(player);
NBTTagCompound savedData = ProxyCommon.getEntityData(getSaveKey(player));
if (savedData != null) { playerData.loadNBTData(savedData); }
Etc.packetPipeline.sendTo(new SyncPlayerPropsPacket(player), (EntityPlayerMP) player);
}
}
and after tons of testing I'm now getting this error
io.netty.handler.codec.DecoderException: java.lang.ArrayIndexOutOfBoundsException: 4
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:80) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:232) [NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:716) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [IntegratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742) [MinecraftServer$2.class:?]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 4
at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:648) ~[InventoryPlayer.class:?]
at net.minecraft.inventory.Slot.getStack(Slot.java:88) ~[Slot.class:?]
at net.minecraft.inventory.Container.getInventory(Container.java:69) ~[Container.class:?]
at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:55) ~[Container.class:?]
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2510) ~[EntityPlayer.class:?]
at com.maplestory.etc.keys.OpenGuiPacket.handleServerSide(OpenGuiPacket.java:44) ~[OpenGuiPacket.class:?]
at com.maplestory.etc.keys.PacketPipeline.decode(PacketPipeline.java:106) ~[PacketPipeline.class:?]
at com.maplestory.etc.keys.PacketPipeline.decode(PacketPipeline.java:1) ~[PacketPipeline.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?]
... 13 more
the packetpipeline error 106 is
pkt.handleServerSide(player);
so now I would think it's based on slots and the container?
so now I would think it's based on slots and the container?
You are getting an array out of bounds error now, which means you are trying something like inventory[4] when there are only 4 (or less) slots in the array. Your network code has been involved in both errors, so it's possible one or more of your packets is messed up, or you aren't properly sending packets from one side to the other, or any number of other things. Look carefully over your packet classes and everywhere that you send a packet, making sure that the packet is only being sent from one side, and that it is the correct side, etc.
You are getting an array out of bounds error now, which means you are trying something like inventory[4] when there are only 4 (or less) slots in the array. Your network code has been involved in both errors, so it's possible one or more of your packets is messed up, or you aren't properly sending packets from one side to the other, or any number of other things. Look carefully over your packet classes and everywhere that you send a packet, making sure that the packet is only being sent from one side, and that it is the correct side, etc.
I tried changing my item inventory inventory class to match as well as my tile entity inventory and your inventory class and yet still. I'm apparently not understanding what you mean. Here's the files if it gives you an 'ah hah' moment.
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
public class Inventory_Equip_Inventory implements IInventory
{
private final String name = "Inventory Equip Inventory";
private final String tagName = "EquipInvTag";
public static final int INV_SIZE = 19;
ItemStack[] inventory = new ItemStack[INV_SIZE];
public Inventory_Equip_Inventory() {
}
@Override
public int getSizeInventory() {
return inventory.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return inventory[slot];
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
if (stack != null) {
if (stack.stackSize > amount) {
stack = stack.splitStack(amount);
markDirty();
} else {
setInventorySlotContents(slot, null);
}
}
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack stack = getStackInSlot(slot);
setInventorySlotContents(slot, null);
return stack;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
markDirty();
}
@Override
public String getInventoryName() {
return name;
}
@Override
public boolean hasCustomInventoryName() {
return name.length() > 0;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public void markDirty() {
for (int i = 0; i < getSizeInventory(); ++i) {
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0)
inventory[i] = null;
}
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return true;
}
@Override
public void openInventory() {}
@Override
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack)
{
//To be specified in slot class
return true;
}
public void writeToNBT(NBTTagCompound compound) {
NBTTagList items = new NBTTagList();
for (int i = 0; i < getSizeInventory(); ++i) {
if (getStackInSlot(i) != null) {
NBTTagCompound item = new NBTTagCompound();
item.setByte("Slot", (byte) i);
getStackInSlot(i).writeToNBT(item);
items.appendTag(item);
}
}
compound.setTag(tagName, items);
}
public void readFromNBT(NBTTagCompound compound) {
NBTTagList items = compound.getTagList(tagName, compound.getId());
for (int i = 0; i < items.tagCount(); ++i) {
NBTTagCompound item = items.getCompoundTagAt(i);
byte slot = item.getByte("Slot");
if (slot >= 0 && slot < getSizeInventory()) {
setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
}
}
}
}
so now I would think it's based on slots and the container?
You are getting an array out of bounds error now, which means you are trying something like inventory[4] when there are only 4 (or less) slots in the array. Your network code has been involved in both errors, so it's possible one or more of your packets is messed up, or you aren't properly sending packets from one side to the other, or any number of other things. Look carefully over your packet classes and everywhere that you send a packet, making sure that the packet is only being sent from one side, and that it is the correct side, etc.
So which class files does that narrow down the errors to. So I know which ones are in need of fixing
current full error
Description: Ticking entity
java.lang.ArrayIndexOutOfBoundsException: 4
at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:648)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:91)
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:253)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2254)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:697)
at net.minecraft.world.World.updateEntity(World.java:2214)
at net.minecraft.world.World.updateEntities(World.java:2064)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:528)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:693)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:648)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:91)
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:253)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2254)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:697)
at net.minecraft.world.World.updateEntity(World.java:2214)
-- Entity being ticked --
Details:
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity ID: 223
Entity Name: Player645
Entity's Exact location: -527.94, 4.00, -260.22
Entity's Block location: World: (-528,4,-261), Chunk: (at 0,0,11 in -33,-17; contains blocks -528,0,-272 to -513,255,-257), Region: (-2,-1; contains chunks -64,-32 to -33,-1, blocks -1024,0,-512 to -513,255,-1)
Entity's Momentum: 0.00, -0.08, 0.00
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:2064)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:528)
So which class files does that narrow down the errors to. So I know which ones are in need of fixing
Did you check your packets like I mentioned earlier? For the array out of bounds exception, you need to look in your error log, go the line that threw the exception (e.g. 119), and then 'trace' all the values and method calls that lead up to that point to determine where the outlier came from. What this means is you try to figure out, by stepping backwards through your code, where the value '4' came from that caused the out of bounds exception.
Well, the error I'm getting now which is edited into my previous comment has no mentions of a specific file of mine. I understand the error involves itemstack.
line 648 (inv player): return aitemstack[par1];
line 88 (slot): return this.inventory.getStackInSlot(this.slotIndex);
line 91 (container): ItemStack itemstack = ((Slot)this.inventorySlots.get(i)).getStack();
line 352 (entity player): this.openContainer.detectAndSendChanges();
I've tinkered with the itemstack involving functions in many of the files but it's still not helping the situation. It's a blatant disagreement I just don't understand
[pre]Caused by: java.lang.ArrayIndexOutOfBoundsException: 4
at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:648) ~[InventoryPlayer.class:?]
at net.minecraft.inventory.Slot.getStack(Slot.java:88) ~[Slot.class:?]
at net.minecraft.inventory.Container.getInventory(Container.java:69) ~[Container.class:?]
at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:55) ~[Container.class:?]
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2510) ~[EntityPlayer.class:?]
at com.maplestory.etc.keys.OpenGuiPacket.handleServerSide(OpenGuiPacket.java:44) ~[OpenGuiPacket.class:?]
at com.maplestory.etc.keys.PacketPipeline.decode(PacketPipeline.java:106) ~[PacketPipeline.class:?]
at com.maplestory.etc.keys.PacketPipeline.decode(PacketPipeline.java:1) ~[PacketPipeline.class:?][/pre]
The ones on the bottom are all from your code, which for whatever reason is providing a value of '4' to some array in EntityPlayer that does not have an array[4] element. My guess is you are accessing the armor slots incorrectly in your Container.
public class Container_Equip_Inventory extends Container
{
private static final int ARMOR_START = Inventory_Equip_Inventory.INV_SIZE, ARMOR_END = ARMOR_START+19,
INV_START = ARMOR_END+1, INV_END = INV_START+26, HOTBAR_START = INV_END+1,
HOTBAR_END = HOTBAR_START+8;
public Container_Equip_Inventory(EntityPlayer player, InventoryPlayer inventoryPlayer, Inventory_Equip_Inventory equipInventory)
{
int i;
// Add ARMOR slots; note you need to make a public version of SlotArmor
// just copy and paste the vanilla code into a new class and change what you need
// Add vanilla PLAYER INVENTORY - just copied/pasted from vanilla classes
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
// Add ACTION BAR - just copied/pasted from vanilla classes
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
}
}
/**
* This should always return true, since custom inventory can be accessed from anywhere
*/
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
* Basically the same as every other container I make, since I define the same constant indices for all of them
*/
public ItemStack transferStackInSlot(EntityPlayer player, int par2)
{
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(par2);
// Either armor slot or custom item slot was clicked
if (par2 < INV_START)
{
// try to place in player inventory / action bar
if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
// Item is in inventory / hotbar, try to place either in custom or armor slots
else
{
// if item is our custom item
if (itemstack1.getItem() instanceof Adamantium_Ore)
{
if (!this.mergeItemStack(itemstack1, 0, Inventory_Equip_Inventory.INV_SIZE, false))
{
return null;
}
}
// if item is armor
else if (itemstack1.getItem() instanceof ItemArmor)
{
int type = ((ItemArmor) itemstack1.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false))
{
return null;
}
}
// item in player's inventory, but not in action bar
else if (par2 >= INV_START && par2 < HOTBAR_START)
{
// place in action bar
if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_START + 1, false))
{
return null;
}
}
// item in action bar - place in player inventory
else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1)
{
if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false))
{
return null;
}
}
}
Rather than having me look through your code, why don't you look through it and see if you can't find the problem? I assume you know how arrays work, i.e. the index starts at zero, so the indices for a "new array[4]" would be array[0]-array[3], and array[4] would be out of bounds, so all you have to do is track down where you try to access array[4]. A sometimes useful trick is to comment out bits of code here and there and see if you can get the code to run - if it does, whatever you commented out was causing the problem.
Rather than having me look through your code, why don't you look through it and see if you can't find the problem? I assume you know how arrays work, i.e. the index starts at zero, so the indices for a "new array[4]" would be array[0]-array[3], and array[4] would be out of bounds, so all you have to do is track down where you try to access array[4]. A sometimes useful trick is to comment out bits of code here and there and see if you can get the code to run - if it does, whatever you commented out was causing the problem.
So the problem was between INV_SIZE, INV_START, and ARMOR_START. At least it was towards the end. There were problems involving packets and one missed registry earlier on. Thanks for the guidance you've given me to arrive to this point Anyone else having problems in 1.7.2, if you haven't already found this, this is an example code for the player inventory by coolalias. https://github.com/coolAlias/Tutorial-1.7.2/commit/94535826fa13a74e560363e499f6dcd0e5e32f39.
btw, is there a way to close the inventory with the keyhandler?
btw, is there a way to close the inventory with the keyhandler?
No and yes; in 1.7.x, you cannot close it (or at least I couldn't figure out how) directly from the keyhandler, but you CAN close it from within the GUI when your custom key is pressed:
// in the Gui class:
@Override
protected void keyTyped(char c, int key) {
// key '1' is Escape, and since my Gui was related to inventory, I also flag the vanilla 'inventory' key to close it just for convenience
if (key == 1 || key == mc.gameSettings.keyBindInventory.getKeyCode() || key == YourKeyHandler.keys[YourKeyHandler.CUSTOM_KEY].getKeyCode()) {
mc.thePlayer.closeScreen();
}
}
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Are you sure you extended Container?
package com.catLord.First;
import java.awt.Component;
import java.awt.Container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
public class ContainerSpiceFurnace extends Container
{
public IInventory furnace;
public ContainerSpiceFurnace(EntityPlayer player ,TileEntitySpiceFurnace furnace)
{
this.addSlotToContainer(new Slot(this.furnace));
}
}
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThat is not the correct "Container" class - you want the Minecraft container, not Java's. Remove all your imports, then, if you are in Eclipse, press ctrl-shift-o to reimport and they should be fixed; otherwise, remove the imports and add them manually.
@SubscribeEventpublic void onKeyInput(KeyInputEvent event) {if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) {if (keys[CUSTOM_INV].isPressed()) {Etc.packetPipeline.sendToServer(new OpenGuiPacket(Etc.GUI_EQUIP));the etc.packetpipeline.sendtoserver line comes up with an error.
public void sendToServer(AbstractPacket message) { this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); this.channels.get(Side.CLIENT).writeAndFlush(message);}both lines are reported in the errorI'm willing to bet more needs to be shown. Either way, im unsure what to trace it back to. This is my first time dealing with this stuff and learning it
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou need to post what the errors say or it's pretty difficult to help. There shouldn't be any errors in the PacketPipeline class (and you actually probably shouldn't be using that now, but that's a post for another day). Double-check your imports, make sure you registered your packet, and if that doesn't help, post your the error text.
hm, I missed registering pipeline in the load (post init was covered). and now the game won't crash but it has a fatal error.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumNull pointer exception at line 119 in your common proxy; that means your open GUI packet went through, but you're missing something when you try to open the GUI. Make sure you return a valid Container for your server element, just as you do a valid Gui for the client element.
hm. I have it as
if (guiId == Etc.GUI_EQUIP) { return new Container_Equip_Inventory(player, player.inventory, ExtendedPlayer.get(player).inventory); }and I tried replacing the container file with your exact coding to see if it'd work, adjusting it to fit what I have and it's still erroring here. The error log menions gui and container. could the gui be the problem or is it for sure the container
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIs that line 119? Is your extended properties class named "ExtendedPlayer"? Is there a field named "inventory" in your extended properties, and did you initialize that field to a non-null value?
yes the return is 119. my extendedplayer is as follows
package com.maplestory.etc.keys; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; import com.maplestory.etc.Etc; import com.maplestory.etc.inventory.Inventory_Equip_Inventory; import com.maplestory.etc.lib.ProxyCommon; public class ExtendedPlayer implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "ExtendedPlayer"; private final EntityPlayer player; public final Inventory_Equip_Inventory inventory = new Inventory_Equip_Inventory(); public ExtendedPlayer(EntityPlayer player) { this.player = player; } public static final void register(EntityPlayer player) { player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player)); } public static final ExtendedPlayer get(EntityPlayer player) { return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME); } @Override public final void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); inventory.writeToNBT(properties); compound.setTag(EXT_PROP_NAME, properties); } @Override public final void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); inventory.readFromNBT(properties); } @Override public void init(Entity entity, World world) {} public void onUpdate() { } private static final String getSaveKey(EntityPlayer player) { return player.getCommandSenderName() + ":" + EXT_PROP_NAME; } public static final void saveProxyData(EntityPlayer player) { NBTTagCompound savedData = new NBTTagCompound(); ExtendedPlayer.get(player).saveNBTData(savedData); ProxyCommon.storeEntityData(getSaveKey(player), savedData); } public static final void loadProxyData(EntityPlayer player) { ExtendedPlayer playerData = ExtendedPlayer.get(player); NBTTagCompound savedData = ProxyCommon.getEntityData(getSaveKey(player)); if (savedData != null) { playerData.loadNBTData(savedData); } Etc.packetPipeline.sendTo(new SyncPlayerPropsPacket(player), (EntityPlayerMP) player); } }and after tons of testing I'm now getting this error
the packetpipeline error 106 is
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou are getting an array out of bounds error now, which means you are trying something like inventory[4] when there are only 4 (or less) slots in the array. Your network code has been involved in both errors, so it's possible one or more of your packets is messed up, or you aren't properly sending packets from one side to the other, or any number of other things. Look carefully over your packet classes and everywhere that you send a packet, making sure that the packet is only being sent from one side, and that it is the correct side, etc.
I tried changing my item inventory inventory class to match as well as my tile entity inventory and your inventory class and yet still. I'm apparently not understanding what you mean. Here's the files if it gives you an 'ah hah' moment.
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; public class Inventory_Equip_Inventory implements IInventory { private final String name = "Inventory Equip Inventory"; private final String tagName = "EquipInvTag"; public static final int INV_SIZE = 19; ItemStack[] inventory = new ItemStack[INV_SIZE]; public Inventory_Equip_Inventory() { } @Override public int getSizeInventory() { return inventory.length; } @Override public ItemStack getStackInSlot(int slot) { return inventory[slot]; } @Override public ItemStack decrStackSize(int slot, int amount) { ItemStack stack = getStackInSlot(slot); if (stack != null) { if (stack.stackSize > amount) { stack = stack.splitStack(amount); markDirty(); } else { setInventorySlotContents(slot, null); } } return stack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack stack = getStackInSlot(slot); setInventorySlotContents(slot, null); return stack; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { inventory[slot] = stack; if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } markDirty(); } @Override public String getInventoryName() { return name; } @Override public boolean hasCustomInventoryName() { return name.length() > 0; } @Override public int getInventoryStackLimit() { return 64; } @Override public void markDirty() { for (int i = 0; i < getSizeInventory(); ++i) { if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) inventory[i] = null; } } @Override public boolean isUseableByPlayer(EntityPlayer player) { return true; } @Override public void openInventory() {} @Override public void closeInventory() {} @Override public boolean isItemValidForSlot(int slot, ItemStack stack) { //To be specified in slot class return true; } public void writeToNBT(NBTTagCompound compound) { NBTTagList items = new NBTTagList(); for (int i = 0; i < getSizeInventory(); ++i) { if (getStackInSlot(i) != null) { NBTTagCompound item = new NBTTagCompound(); item.setByte("Slot", (byte) i); getStackInSlot(i).writeToNBT(item); items.appendTag(item); } } compound.setTag(tagName, items); } public void readFromNBT(NBTTagCompound compound) { NBTTagList items = compound.getTagList(tagName, compound.getId()); for (int i = 0; i < items.tagCount(); ++i) { NBTTagCompound item = items.getCompoundTagAt(i); byte slot = item.getByte("Slot"); if (slot >= 0 && slot < getSizeInventory()) { setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item)); } } } }import com.maplestory.etc.items.Adamantium_Ore; 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.ItemArmor; import net.minecraft.item.ItemStack; public class Container_Equip_Inventory extends Container { private static final int ARMOR_START = Inventory_Equip_Inventory.INV_SIZE, ARMOR_END = ARMOR_START+19, INV_START = ARMOR_END+1, INV_END = INV_START+26, HOTBAR_START = INV_END+1, HOTBAR_END = HOTBAR_START+8; public Container_Equip_Inventory(EntityPlayer player, InventoryPlayer inventoryPlayer, Inventory_Equip_Inventory equipInventory) { int i; //Location yet to be determined this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50)); for (i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142)); } } @Override public boolean canInteractWith(EntityPlayer player) { return true; } public ItemStack transferStackInSlot(EntityPlayer player, int par2) { ItemStack itemstack = null; Slot slot = (Slot) this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (par2 < INV_START) { if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else { if (itemstack1.getItem() instanceof Adamantium_Ore) { if (!this.mergeItemStack(itemstack1, 0, Inventory_Equip_Inventory.INV_SIZE, false)) { return null; } } else if (itemstack1.getItem() instanceof ItemArmor) { int type = ((ItemArmor) itemstack1.getItem()).armorType; if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false)) { return null; } } else if (par2 >= INV_START && par2 < HOTBAR_START) { if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_START + 1, false)) { return null; } } else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1) { if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false)) { return null; } } } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack) null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(player, itemstack1); } return itemstack; } }So which class files does that narrow down the errors to. So I know which ones are in need of fixing
current full error
Description: Ticking entity
java.lang.ArrayIndexOutOfBoundsException: 4
at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:648)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:91)
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:253)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2254)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:697)
at net.minecraft.world.World.updateEntity(World.java:2214)
at net.minecraft.world.World.updateEntities(World.java:2064)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:528)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:693)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:648)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:91)
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:253)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2254)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:697)
at net.minecraft.world.World.updateEntity(World.java:2214)
-- Entity being ticked --
Details:
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity ID: 223
Entity Name: Player645
Entity's Exact location: -527.94, 4.00, -260.22
Entity's Block location: World: (-528,4,-261), Chunk: (at 0,0,11 in -33,-17; contains blocks -528,0,-272 to -513,255,-257), Region: (-2,-1; contains chunks -64,-32 to -33,-1, blocks -1024,0,-512 to -513,255,-1)
Entity's Momentum: 0.00, -0.08, 0.00
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:2064)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:528)
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumDid you check your packets like I mentioned earlier? For the array out of bounds exception, you need to look in your error log, go the line that threw the exception (e.g. 119), and then 'trace' all the values and method calls that lead up to that point to determine where the outlier came from. What this means is you try to figure out, by stepping backwards through your code, where the value '4' came from that caused the out of bounds exception.
Well, the error I'm getting now which is edited into my previous comment has no mentions of a specific file of mine. I understand the error involves itemstack.
line 648 (inv player): return aitemstack[par1];
line 88 (slot): return this.inventory.getStackInSlot(this.slotIndex);
line 91 (container): ItemStack itemstack = ((Slot)this.inventorySlots.get(i)).getStack();
line 352 (entity player): this.openContainer.detectAndSendChanges();
I've tinkered with the itemstack involving functions in many of the files but it's still not helping the situation. It's a blatant disagreement I just don't understand
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThe ones on the bottom are all from your code, which for whatever reason is providing a value of '4' to some array in EntityPlayer that does not have an array[4] element. My guess is you are accessing the armor slots incorrectly in your Container.
package com.maplestory.etc.inventory;
import com.maplestory.etc.items.Adamantium_Ore;
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.ItemArmor;
import net.minecraft.item.ItemStack;
public class Container_Equip_Inventory extends Container
{
private static final int ARMOR_START = Inventory_Equip_Inventory.INV_SIZE, ARMOR_END = ARMOR_START+19,
INV_START = ARMOR_END+1, INV_END = INV_START+26, HOTBAR_START = INV_END+1,
HOTBAR_END = HOTBAR_START+8;
public Container_Equip_Inventory(EntityPlayer player, InventoryPlayer inventoryPlayer, Inventory_Equip_Inventory equipInventory)
{
int i;
// Add ARMOR slots; note you need to make a public version of SlotArmor
// just copy and paste the vanilla code into a new class and change what you need
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
this.addSlotToContainer(new SlotCap(player, inventoryPlayer, inventoryPlayer.getSizeInventory(), 8, 80, 50));
// Add vanilla PLAYER INVENTORY - just copied/pasted from vanilla classes
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
// Add ACTION BAR - just copied/pasted from vanilla classes
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
}
}
/**
* This should always return true, since custom inventory can be accessed from anywhere
*/
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
* Basically the same as every other container I make, since I define the same constant indices for all of them
*/
public ItemStack transferStackInSlot(EntityPlayer player, int par2)
{
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(par2);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
// Either armor slot or custom item slot was clicked
if (par2 < INV_START)
{
// try to place in player inventory / action bar
if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
// Item is in inventory / hotbar, try to place either in custom or armor slots
else
{
// if item is our custom item
if (itemstack1.getItem() instanceof Adamantium_Ore)
{
if (!this.mergeItemStack(itemstack1, 0, Inventory_Equip_Inventory.INV_SIZE, false))
{
return null;
}
}
// if item is armor
else if (itemstack1.getItem() instanceof ItemArmor)
{
int type = ((ItemArmor) itemstack1.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false))
{
return null;
}
}
// item in player's inventory, but not in action bar
else if (par2 >= INV_START && par2 < HOTBAR_START)
{
// place in action bar
if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_START + 1, false))
{
return null;
}
}
// item in action bar - place in player inventory
else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1)
{
if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false))
{
return null;
}
}
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack) null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(player, itemstack1);
}
return itemstack;
}
}
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumSo the problem was between INV_SIZE, INV_START, and ARMOR_START. At least it was towards the end. There were problems involving packets and one missed registry earlier on. Thanks for the guidance you've given me to arrive to this point
btw, is there a way to close the inventory with the keyhandler?
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumNo and yes; in 1.7.x, you cannot close it (or at least I couldn't figure out how) directly from the keyhandler, but you CAN close it from within the GUI when your custom key is pressed:
// in the Gui class: @Override protected void keyTyped(char c, int key) { // key '1' is Escape, and since my Gui was related to inventory, I also flag the vanilla 'inventory' key to close it just for convenience if (key == 1 || key == mc.gameSettings.keyBindInventory.getKeyCode() || key == YourKeyHandler.keys[YourKeyHandler.CUSTOM_KEY].getKeyCode()) { mc.thePlayer.closeScreen(); } }