net.minecraft.inventory.container.INamedContainerProvider Java Examples
The following examples show how to use
net.minecraft.inventory.container.INamedContainerProvider.
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: 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 #2
Source File: ModificationTable.java From MiningGadgets with MIT License | 5 votes |
@Override public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult result) { if (!world.isRemote) { TileEntity tileEntity = world.getTileEntity(pos); if (tileEntity instanceof INamedContainerProvider) { NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos()); } else { throw new IllegalStateException("Our named container provider is missing!"); } return ActionResultType.SUCCESS; } return ActionResultType.SUCCESS; }
Example #3
Source File: SawmillBlock.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult blockRayTraceResult) { if (worldIn.isRemote) return ActionResultType.SUCCESS; TileEntity tileEntity = worldIn.getTileEntity(pos); if (!(tileEntity instanceof INamedContainerProvider)) return ActionResultType.FAIL; NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity); return ActionResultType.SUCCESS; }
Example #4
Source File: DryingRackBlock.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Deprecated @Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult blockRayTraceResult) { if (worldIn.isRemote) return ActionResultType.SUCCESS; TileEntity tileEntity = worldIn.getTileEntity(pos); if (!(tileEntity instanceof INamedContainerProvider)) return ActionResultType.FAIL; NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity); return ActionResultType.SUCCESS; }
Example #5
Source File: ServerUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 4 votes |
public static void openContainer(ServerPlayerEntity player, INamedContainerProvider containerProvider) { openContainer(player, containerProvider, e -> { }); }