net.minecraft.inventory.container.Container Java Examples
The following examples show how to use
net.minecraft.inventory.container.Container.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PacketGhostSlot.java From MiningGadgets with MIT License | 6 votes |
public static void handle(PacketGhostSlot msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity sender = ctx.get().getSender(); if (sender == null) return; Container container = sender.openContainer; if (container == null) return; Slot slot = container.inventorySlots.get(msg.slotNumber); if (slot instanceof GhostSlot) slot.putStack(msg.stack); }); ctx.get().setPacketHandled(true); }
Example #2
Source File: ClientPacketHandler.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
@SuppressWarnings ("unchecked") private void handleOpenContainer(PacketCustom packet, Minecraft mc) { ContainerType<?> rawType = packet.readRegistryIdUnsafe(ForgeRegistries.CONTAINERS); int windowId = packet.readVarInt(); ITextComponent name = packet.readTextComponent(); if (rawType instanceof ICCLContainerType<?>) { ICCLContainerType<?> type = (ICCLContainerType<?>) rawType; ScreenManager.getScreenFactory(rawType, mc, windowId, name)// .map(e -> (ScreenManager.IScreenFactory<Container, ?>) e)// .ifPresent(screenFactory -> { Container container = type.create(windowId, Minecraft.getInstance().player.inventory, packet); Screen screen = screenFactory.create(container, mc.player.inventory, name); mc.player.openContainer = ((IHasContainer<?>) screen).getContainer(); mc.displayGuiScreen(screen); }); } }
Example #3
Source File: ServerUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public static void openContainer(ServerPlayerEntity player, INamedContainerProvider containerProvider, Consumer<MCDataOutput> packetConsumer) { if (player.world.isRemote()) { return; } player.closeContainer(); player.getNextWindowId(); int containerId = player.currentWindowId; Container container = containerProvider.createMenu(containerId, player.inventory, player); ContainerType<?> type = container.getType(); PacketCustom packet = new PacketCustom(CCLNetwork.NET_CHANNEL, C_OPEN_CONTAINER); packet.writeRegistryIdUnsafe(ForgeRegistries.CONTAINERS, type); packet.writeVarInt(containerId); packet.writeTextComponent(containerProvider.getDisplayName()); packetConsumer.accept(packet); packet.sendToPlayer(player); player.openContainer = container; player.openContainer.addListener(player); MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container)); }
Example #4
Source File: PacketOpenFilterContainer.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketOpenFilterContainer msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity sender = ctx.get().getSender(); if (sender == null) return; Container container = sender.openContainer; if (container == null) return; ItemStack stack = MiningGadget.getGadget(sender); if( stack.isEmpty() ) return; ItemStackHandler ghostInventory = new ItemStackHandler(30) { @Override protected void onContentsChanged(int slot) { stack.getOrCreateTag().put(MiningProperties.KEY_FILTERS, serializeNBT()); } }; ghostInventory.deserializeNBT(stack.getOrCreateChildTag(MiningProperties.KEY_FILTERS)); sender.openContainer(new SimpleNamedContainerProvider( (windowId, playerInventory, playerEntity) -> new FilterContainer(windowId, playerInventory, ghostInventory), new StringTextComponent("") )); }); ctx.get().setPacketHandled(true); }
Example #5
Source File: ModificationTableTileEntity.java From MiningGadgets with MIT License | 4 votes |
@Nullable @Override public Container createMenu(int i, PlayerInventory playerInventory, PlayerEntity playerEntity) { return new ModificationTableContainer(i, world, pos, playerInventory); }
Example #6
Source File: ICCLContainerType.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 4 votes |
static <T extends Container> ContainerType<T> create(ICCLContainerFactory<T> factory) { return new CCLContainerType<>(factory); }
Example #7
Source File: SawmillTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Nullable @Override public Container createMenu(int windowId, PlayerInventory playerInventory, PlayerEntity player) { return new SawmillContainer(windowId, this, playerInventory); }
Example #8
Source File: DryingRackTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Nullable @Override public Container createMenu(int windowId, PlayerInventory playerInventory, PlayerEntity player) { return new DryingRackContainer(windowId, this, playerInventory); }