Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

I don't know what is causing this, but you can try using player.inventory.mainInventory[number] = null;

  • Author

Produces same exception. It's weird because it does actually set it to null.

  • Author

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

 

 

  • Author

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

}

}

}

}

 

 

  • Author

That must be it, thanks. Can you give an example on what would be in the packet handler to open the GUI?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.