Search in sources :

Example 11 with Container

use of net.minecraft.inventory.Container in project Engine by VoltzEngine-Project.

the class PacketGui method handleServerSide.

@Override
public void handleServerSide(EntityPlayer player) {
    Container container = player.openContainer;
    Location location = new Location(player);
    if (container instanceof IPacketIDReceiver) {
        if (((IPacketIDReceiver) container).shouldReadPacket(player, location, this)) {
            try {
                IPacketIDReceiver receiver = (IPacketIDReceiver) container;
                ByteBuf buf = data().slice();
                int id;
                try {
                    id = buf.readInt();
                } catch (IndexOutOfBoundsException ex) {
                    Engine.instance.logger().error(new PacketIDException(location));
                    return;
                }
                receiver.read(buf, id, player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
                Engine.instance.logger().error("Error: ", e);
            } catch (NullPointerException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Null pointer while reading data", e));
                Engine.instance.logger().error("Error: ", e);
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                Engine.instance.logger().error("Error: ", e);
            }
        } else {
            Engine.instance.logger().error("Error: " + container + " rejected packet " + this + " due to invalid conditions.");
        }
    } else if (container instanceof IPacketReceiver) {
        if (((IPacketReceiver) container).shouldReadPacket(player, location, this)) {
            try {
                IPacketReceiver receiver = (IPacketReceiver) container;
                receiver.read(data().slice(), player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                e.printStackTrace();
            }
        } else {
            Engine.instance.logger().error("Error: " + container + " rejected packet " + this + " due to invalid conditions.");
        }
    } else {
        Engine.instance.logger().error(new PacketTileReadException(location, "Unsupported action for " + container));
    }
}
Also used : IPacketReceiver(com.builtbroken.mc.core.network.IPacketReceiver) Container(net.minecraft.inventory.Container) IPacketIDReceiver(com.builtbroken.mc.core.network.IPacketIDReceiver) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) ByteBuf(io.netty.buffer.ByteBuf) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException) Location(com.builtbroken.mc.imp.transform.vector.Location) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException)

Aggregations

Container (net.minecraft.inventory.Container)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 IInventory (net.minecraft.inventory.IInventory)3 ItemStack (net.minecraft.item.ItemStack)3 ByteBuf (io.netty.buffer.ByteBuf)2 ContainerBetterStorage (net.mcft.copy.betterstorage.container.ContainerBetterStorage)2 GuiContainer (net.minecraft.client.gui.inventory.GuiContainer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 FakePlayer (net.minecraftforge.common.util.FakePlayer)2 IPacketIDReceiver (com.builtbroken.mc.core.network.IPacketIDReceiver)1 IPacketReceiver (com.builtbroken.mc.core.network.IPacketReceiver)1 PacketIDException (com.builtbroken.mc.core.network.ex.PacketIDException)1 PacketTileReadException (com.builtbroken.mc.core.network.ex.PacketTileReadException)1 Location (com.builtbroken.mc.imp.transform.vector.Location)1 JsonObject (com.google.gson.JsonObject)1 ContainerSeedStorageBase (com.infinityraider.agricraft.container.ContainerSeedStorageBase)1 ISeedStorageControllable (com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable)1 Side (cpw.mods.fml.relauncher.Side)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1