类net.minecraft.inventory.container.INamedContainerProvider源码实例Demo

下面列出了怎么用net.minecraft.inventory.container.INamedContainerProvider的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: CodeChickenLib   文件: ServerUtils.java
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));
}
 
源代码2 项目: MiningGadgets   文件: ModificationTable.java
@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;
}
 
源代码3 项目: Survivalist   文件: SawmillBlock.java
@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;
}
 
源代码4 项目: Survivalist   文件: DryingRackBlock.java
@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;
}
 
源代码5 项目: CodeChickenLib   文件: ServerUtils.java
public static void openContainer(ServerPlayerEntity player, INamedContainerProvider containerProvider) {
    openContainer(player, containerProvider, e -> {
    });
}