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;
}
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;
}
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);
}
}
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();
}
}
}
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);
}
}
Aggregations