Search in sources :

Example 1 with Inventory

use of net.minecraft.world.entity.player.Inventory in project MinecraftForge by MinecraftForge.

the class ContainerTypeTest method onRightClick.

private void onRightClick(PlayerInteractEvent.RightClickBlock event) {
    if (!event.getWorld().isClientSide && event.getHand() == InteractionHand.MAIN_HAND) {
        if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.SPONGE) {
            String text = "Hello World!";
            NetworkHooks.openGui((ServerPlayer) event.getPlayer(), new MenuProvider() {

                @Override
                public AbstractContainerMenu createMenu(int p_createMenu_1_, Inventory p_createMenu_2_, Player p_createMenu_3_) {
                    SimpleContainer inv = new SimpleContainer(9);
                    for (int i = 0; i < inv.getContainerSize(); i++) {
                        inv.setItem(i, new ItemStack(Items.DIAMOND));
                    }
                    return new TestContainer(p_createMenu_1_, inv, text);
                }

                @Override
                public Component getDisplayName() {
                    return new TextComponent("Test");
                }
            }, extraData -> {
                extraData.writeUtf(text);
            });
        }
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ServerPlayer(net.minecraft.server.level.ServerPlayer) Player(net.minecraft.world.entity.player.Player) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) SimpleContainer(net.minecraft.world.SimpleContainer) ItemStack(net.minecraft.world.item.ItemStack) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) MenuProvider(net.minecraft.world.MenuProvider) Inventory(net.minecraft.world.entity.player.Inventory)

Aggregations

Component (net.minecraft.network.chat.Component)1 TextComponent (net.minecraft.network.chat.TextComponent)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 MenuProvider (net.minecraft.world.MenuProvider)1 SimpleContainer (net.minecraft.world.SimpleContainer)1 Inventory (net.minecraft.world.entity.player.Inventory)1 Player (net.minecraft.world.entity.player.Player)1 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1 ItemStack (net.minecraft.world.item.ItemStack)1