Search in sources :

Example 1 with Container

use of net.minecraft.inventory.Container in project BetterStorage by copygirl.

the class ItemKeyring method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if (world.isRemote || !player.isSneaking())
        return stack;
    String title = StackUtils.get(stack, "", "display", "Name");
    int protectedSlot = player.inventory.currentItem;
    Container container = new ContainerKeyring(player, title, protectedSlot);
    PlayerUtils.openGui(player, Constants.containerKeyring, protectedSlot, 1, title, container);
    return stack;
}
Also used : Container(net.minecraft.inventory.Container) ContainerKeyring(net.mcft.copy.betterstorage.container.ContainerKeyring)

Example 2 with Container

use of net.minecraft.inventory.Container in project LogisticsPipes by RS485.

the class ImmibisCraftingTableMk2 method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    try {
        if (tileAutoCraftingMk2.isInstance(tile)) {
            // Import recipeInputs
            ItemStack[][] recipe = (ItemStack[][]) tileAutoCraftingMk2.getField("recipeInputs").get(tile);
            // Not really a AutoCraftingInventory, but same content
            InventoryCrafting tempCraftingInv = new InventoryCrafting(new Container() {

                @Override
                public boolean canInteractWith(EntityPlayer entityplayer) {
                    return false;
                }

                @Override
                public void onCraftMatrixChanged(IInventory par1iInventory) {
                }
            }, 3, 3);
            for (int i = 0; i < 9; i++) {
                if (recipe[i].length > 0) {
                    tempCraftingInv.setInventorySlotContents(i, recipe[i][0]);
                    inventory.setInventorySlotContents(i, recipe[i][0]);
                } else {
                    inventory.clearInventorySlotContents(i);
                }
            }
            // Compact
            int slotCount = 0;
            for (int i = 0; i < 9; i++) {
                ItemStack slotStack = inventory.getStackInSlot(i);
                inventory.clearInventorySlotContents(i);
                if (slotStack != null && slotStack.getItem() != null) {
                    int count = 1;
                    for (int j = i + 1; j < 9; j++) {
                        ItemStack tempStack = inventory.getStackInSlot(j);
                        if (tempStack != null && ItemIdentifier.get(slotStack).equals(ItemIdentifier.get(tempStack))) {
                            inventory.clearInventorySlotContents(j);
                            count++;
                        }
                    }
                    slotStack.stackSize = count;
                    inventory.setInventorySlotContents(slotCount, slotStack);
                    slotCount++;
                }
            }
            ItemStack result = null;
            for (IRecipe r : CraftingUtil.getRecipeList()) {
                if (r.matches(tempCraftingInv, tile.getWorldObj())) {
                    result = r.getCraftingResult(tempCraftingInv);
                    break;
                }
            }
            inventory.setInventorySlotContents(9, result);
            return true;
        }
    } catch (IllegalArgumentException | NoSuchFieldException e) {
        LogisticsPipes.log.fatal("Error while importing recipe from Tubestuff's AutoCraftingMk2");
        e.printStackTrace();
    } catch (Exception e) {
        LogisticsPipes.log.error("Got a problem on ImmibisCraftingTableMk2 CraftingRecipeProvider:");
        LogisticsPipes.log.error(e.getMessage());
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IRecipe(net.minecraft.item.crafting.IRecipe) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) Container(net.minecraft.inventory.Container) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Container

use of net.minecraft.inventory.Container in project MinecraftForge by MinecraftForge.

the class FMLNetworkHandler method openGui.

public static void openGui(EntityPlayer entityPlayer, Object mod, int modGuiId, World world, int x, int y, int z) {
    ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
    if (entityPlayer instanceof EntityPlayerMP && !(entityPlayer instanceof FakePlayer)) {
        EntityPlayerMP entityPlayerMP = (EntityPlayerMP) entityPlayer;
        Container remoteGuiContainer = NetworkRegistry.INSTANCE.getRemoteGuiContainer(mc, entityPlayerMP, modGuiId, world, x, y, z);
        if (remoteGuiContainer != null) {
            entityPlayerMP.getNextWindowId();
            entityPlayerMP.closeContainer();
            int windowId = entityPlayerMP.currentWindowId;
            FMLMessage.OpenGui openGui = new FMLMessage.OpenGui(windowId, mc.getModId(), modGuiId, x, y, z);
            EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
            embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.PLAYER);
            embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityPlayerMP);
            embeddedChannel.writeOutbound(openGui);
            entityPlayerMP.openContainer = remoteGuiContainer;
            entityPlayerMP.openContainer.windowId = windowId;
            entityPlayerMP.openContainer.addListener(entityPlayerMP);
            net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open(entityPlayer, entityPlayer.openContainer));
        }
    } else if (entityPlayer instanceof FakePlayer) {
    // NO OP - I won't even log a message!
    } else if (FMLCommonHandler.instance().getSide().equals(Side.CLIENT)) {
        Object guiContainer = NetworkRegistry.INSTANCE.getLocalGuiContainer(mc, entityPlayer, modGuiId, world, x, y, z);
        FMLCommonHandler.instance().showGuiScreen(guiContainer);
    } else {
        FMLLog.fine("Invalid attempt to open a local GUI on a dedicated server. This is likely a bug. GUI ID: %s,%d", mc.getModId(), modGuiId);
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) FMLEmbeddedChannel(net.minecraftforge.fml.common.network.FMLEmbeddedChannel) FakePlayer(net.minecraftforge.common.util.FakePlayer) ModContainer(net.minecraftforge.fml.common.ModContainer) FMLContainer(net.minecraftforge.fml.common.FMLContainer) Container(net.minecraft.inventory.Container) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) JsonObject(com.google.gson.JsonObject)

Example 4 with Container

use of net.minecraft.inventory.Container in project AgriCraft by AgriCraft.

the class MessageGuiSeedStorageClearSeed method processMessage.

@Override
protected void processMessage(MessageContext ctx) {
    final Container container = this.player.openContainer;
    if (container instanceof ContainerSeedStorageBase) {
        final ContainerSeedStorageBase storage = ((ContainerSeedStorageBase) container);
        final TileEntity tileEntity = storage.getTile();
        if (tileEntity instanceof ISeedStorageControllable) {
            ((ISeedStorageControllable) tileEntity).clearLockedSeed();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Container(net.minecraft.inventory.Container) ISeedStorageControllable(com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable) ContainerSeedStorageBase(com.infinityraider.agricraft.container.ContainerSeedStorageBase)

Example 5 with Container

use of net.minecraft.inventory.Container in project RecurrentComplex by Ivorforce.

the class IvGuiRegistry method openGui.

// From FMLNetworkHandler.openGui
public void openGui(EntityPlayer entityPlayer, String modid, int modGuiId, ByteBuf data) {
    IvGuiHandler handler = handlers.get(modid);
    if (handler == null)
        return;
    if (entityPlayer instanceof EntityPlayerMP && !(entityPlayer instanceof FakePlayer)) {
        EntityPlayerMP entityPlayerMP = (EntityPlayerMP) entityPlayer;
        ByteBuf dataCopy = data.copy();
        Container remoteGuiContainer = handler.getServerGuiElement(modGuiId, entityPlayerMP, data);
        entityPlayerMP.getNextWindowId();
        entityPlayerMP.closeContainer();
        int windowId = entityPlayerMP.currentWindowId;
        RecurrentComplex.network.sendTo(new PacketOpenGui(windowId, modid, modGuiId, dataCopy), entityPlayerMP);
        if (// If null, it's client only
        remoteGuiContainer != null) {
            entityPlayerMP.openContainer = remoteGuiContainer;
            entityPlayerMP.openContainer.windowId = windowId;
            entityPlayerMP.openContainer.addListener(entityPlayerMP);
        }
    } else if (entityPlayer instanceof FakePlayer) {
    // NO OP - I won't even log a message!
    } else if (FMLCommonHandler.instance().getSide().equals(Side.CLIENT)) {
        RecurrentComplex.network.sendToServer(new PacketOpenGui(0, modid, modGuiId, data));
    } else {
        FMLLog.fine("Invalid attempt to open a local GUI on a dedicated server. This is likely a bug. GUI ID: %s,%d", modid, modGuiId);
    }
}
Also used : Container(net.minecraft.inventory.Container) PacketOpenGui(ivorius.reccomplex.network.PacketOpenGui) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ByteBuf(io.netty.buffer.ByteBuf) FakePlayer(net.minecraftforge.common.util.FakePlayer)

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