Jump to content

[1.7.10] Can't manipulate player's inventory beyond slot 8


Recommended Posts

Posted

In my packet handler, I'm getting an exception every time I attempt to manipulate any item in a slot that isn't the hot-bar (0-8 is fine, 9-40 causes exception)

 

Example, this code (line 16):

 

 

 

public class SimplePacket implements IMessage {

public SimplePacket() {}

 

@Override

public void fromBytes(ByteBuf buf) {}

 

    @Override

    public void toBytes(ByteBuf buf) {}

 

    public static class Handler implements IMessageHandler<SimplePacket, IMessage> {

 

        @Override

        public IMessage onMessage(SimplePacket message, MessageContext ctx) {

        if (ctx.side.isServer()) {

EntityPlayerMP player = ctx.getServerHandler().playerEntity;

player.inventory.setInventorySlotContents(9, null);

        }

        return null;

        }

    }

}

 

 

 

produces this exception (yes there's an item in slot 9):

 

 

 

java.lang.IndexOutOfBoundsException: Index: 9, Size: 0

at java.util.ArrayList.rangeCheck(Unknown Source)

at java.util.ArrayList.get(Unknown Source)

at net.minecraft.inventory.Container.getSlot(Container.java:130)

at net.minecraft.inventory.Container.putStackInSlot(Container.java:547)

at net.minecraft.client.network.NetHandlerPlayClient.handleSetSlot(NetHandlerPlayClient.java:1154)

at net.minecraft.network.play.server.S2FPacketSetSlot.processPacket(S2FPacketSetSlot.java:33)

at net.minecraft.network.play.server.S2FPacketSetSlot.processPacket(S2FPacketSetSlot.java:79)

at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)

at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1682)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028)

at net.minecraft.client.Minecraft.run(Minecraft.java:951)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

 

 

Any ideas? Need more information?

Posted

It's being sent from a GUI extending GuiContainer

 

via:

 

 

private void dropItem()

{

ProjectCW.INSTANCE.sendToServer(new SimplePacket());

}

 

 

 

register code in main:

 

 

 

public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(modid);

 

@EventHandler

    public void init(FMLInitializationEvent event)

    {

            INSTANCE.registerMessage(SimplePacket.Handler.class, SimplePacket.class, 0, Side.SERVER);

 

 

Posted

GUI handler:

 

 

 

public class HandlerGUI implements IGuiHandler {

 

@Override

public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

switch(ID) {

case ProjectCW.GUIIDPipboy:

return new ContainerPlayerInventory(player.inventory);

}

return null;

}

 

@Override

public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

switch(ID) {

case ProjectCW.GUIIDPipboy:

return new GUIPipboy(player.inventory);

case ProjectCW.GUIIDGameMenu:

return new GUIGameMenu();

}

return null;

}

}

 

 

 

Opening GUI:

 

 

 

@SubscribeEvent

public void onKeyInput(InputEvent.KeyInputEvent event) {

if (keys[PIPBOY].isPressed()) {

if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) {

if(!(Minecraft.getMinecraft().currentScreen instanceof GUIPipboy)) {

World world = Minecraft.getMinecraft().theWorld;

EntityPlayer player = Minecraft.getMinecraft().thePlayer;

player.openGui(ProjectCW.instance, ProjectCW.GUIIDPipboy, world, 0, 0, 0);

}

}

}

}

 

 

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.