Search in sources :

Example 1 with AbstractContainerMenu

use of net.minecraft.world.inventory.AbstractContainerMenu in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method setSlot.

@Override
public void setSlot(Player player, int slot, ItemStack itemStack, boolean playerOnly) {
    AbstractContainerMenu menu = ((CraftPlayer) player).getHandle().containerMenu;
    int windowId = playerOnly ? 0 : menu.containerId;
    send(player, new ClientboundContainerSetSlotPacket(windowId, menu.incrementStateId(), slot, CraftItemStack.asNMSCopy(itemStack)));
}
Also used : AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu)

Example 2 with AbstractContainerMenu

use of net.minecraft.world.inventory.AbstractContainerMenu in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method setSlot.

@Override
public void setSlot(Player player, int slot, ItemStack itemStack, boolean playerOnly) {
    AbstractContainerMenu menu = ((CraftPlayer) player).getHandle().containerMenu;
    int windowId = playerOnly ? 0 : menu.containerId;
    send(player, new ClientboundContainerSetSlotPacket(windowId, menu.incrementStateId(), slot, CraftItemStack.asNMSCopy(itemStack)));
}
Also used : AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu)

Example 3 with AbstractContainerMenu

use of net.minecraft.world.inventory.AbstractContainerMenu in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        MenuType<?> customSize = MenuType.GENERIC_9x1;
        switch(this.getContainerSize()) {
            case 18:
                customSize = MenuType.GENERIC_9x2;
                break;
            case 27:
                customSize = MenuType.GENERIC_9x3;
                break;
            case 36:
                customSize = MenuType.GENERIC_9x4;
                break;
            case 45:
                customSize = MenuType.GENERIC_9x5;
                break;
            case 54:
                customSize = MenuType.GENERIC_9x6;
                break;
        }
        entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
        entityPlayer.containerMenu = container;
        entityPlayer.initMenu(container);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftContainer)

Example 4 with AbstractContainerMenu

use of net.minecraft.world.inventory.AbstractContainerMenu in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        MenuType<?> customSize = MenuType.GENERIC_9x1;
        switch(this.getContainerSize()) {
            case 18:
                customSize = MenuType.GENERIC_9x2;
                break;
            case 27:
                customSize = MenuType.GENERIC_9x3;
                break;
            case 36:
                customSize = MenuType.GENERIC_9x4;
                break;
            case 45:
                customSize = MenuType.GENERIC_9x5;
                break;
            case 54:
                customSize = MenuType.GENERIC_9x6;
                break;
        }
        entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
        entityPlayer.containerMenu = container;
        entityPlayer.initMenu(container);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftContainer)

Example 5 with AbstractContainerMenu

use of net.minecraft.world.inventory.AbstractContainerMenu in project SpongeCommon by SpongePowered.

the class InventoryEventFactory method displayContainer.

@org.checkerframework.checker.nullness.qual.Nullable
public static AbstractContainerMenu displayContainer(final ServerPlayer player, final Inventory inventory, final Component displayName) {
    final net.minecraft.world.inventory.AbstractContainerMenu previousContainer = player.containerMenu;
    final net.minecraft.world.inventory.AbstractContainerMenu container;
    Optional<ViewableInventory> viewable = inventory.asViewable();
    if (viewable.isPresent()) {
        if (viewable.get() instanceof MenuProvider) {
            MenuProvider namedContainerProvider = (MenuProvider) viewable.get();
            if (displayName != null) {
                namedContainerProvider = new SimpleMenuProvider(namedContainerProvider, SpongeAdventure.asVanilla(displayName));
            }
            player.openMenu(namedContainerProvider);
        } else if (viewable.get() instanceof CarriedInventory) {
            Optional carrier = ((CarriedInventory) viewable.get()).carrier();
            if (carrier.get() instanceof AbstractHorse) {
                player.openHorseInventory(((AbstractHorse) carrier.get()), ((Container) viewable.get()));
            }
        } else if (viewable.get() instanceof Merchant) {
            Merchant merchant = (Merchant) viewable.get();
            net.minecraft.network.chat.Component display = null;
            int level = 0;
            if (merchant instanceof Villager) {
                display = ((Villager) merchant).getDisplayName();
                level = ((Villager) merchant).getVillagerData().getLevel();
            } else if (merchant instanceof WanderingTrader) {
                display = ((WanderingTrader) merchant).getDisplayName();
                level = 1;
            }
            if (displayName != null) {
                display = SpongeAdventure.asVanilla(displayName);
            }
            OptionalInt containerId = player.openMenu(new SimpleMenuProvider((id, playerInv, p) -> new MerchantMenu(id, playerInv, merchant), display));
            if (containerId.isPresent() && !merchant.getOffers().isEmpty()) {
                player.sendMerchantOffers(containerId.getAsInt(), merchant.getOffers(), level, merchant.getVillagerXp(), merchant.showProgressBar(), merchant.canRestock());
            }
        }
    }
    container = player.containerMenu;
    if (previousContainer == container) {
        return null;
    }
    if (!InventoryEventFactory.callInteractContainerOpenEvent(player)) {
        return null;
    }
    if (container instanceof ContainerBridge) {
        // This overwrites the normal container behaviour and allows viewing
        // inventories that are more than 8 blocks away
        // This currently actually only works for the Containers mixed into
        // by InteractableContainerMixin ; but throws no errors for other
        // containers
        // Allow viewing inventory; except when dead
        ((ContainerBridge) container).bridge$setCanInteractWith(p -> !p.removed);
    }
    return container;
}
Also used : EnchantItemEvent(org.spongepowered.api.event.item.inventory.EnchantItemEvent) LivingEntity(net.minecraft.world.entity.LivingEntity) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) SimpleMenuProvider(net.minecraft.world.SimpleMenuProvider) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) ContainerBridge(org.spongepowered.common.bridge.world.inventory.container.ContainerBridge) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) Enchantment(org.spongepowered.api.item.enchantment.Enchantment) Villager(net.minecraft.world.entity.npc.Villager) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) PlayerInventoryTransaction(org.spongepowered.common.event.tracking.context.transaction.inventory.PlayerInventoryTransaction) MerchantMenu(net.minecraft.world.inventory.MerchantMenu) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) Transaction(org.spongepowered.api.data.Transaction) HopperBlockEntity(net.minecraft.world.level.block.entity.HopperBlockEntity) InteractContainerEvent(org.spongepowered.api.event.item.inventory.container.InteractContainerEvent) Merchant(net.minecraft.world.item.trading.Merchant) Player(net.minecraft.world.entity.player.Player) EnchantmentInstance(net.minecraft.world.item.enchantment.EnchantmentInstance) InventoryUtil(org.spongepowered.common.inventory.util.InventoryUtil) List(java.util.List) ItemEntity(net.minecraft.world.entity.item.ItemEntity) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Optional(java.util.Optional) MenuProvider(net.minecraft.world.MenuProvider) EnchantmentMenu(net.minecraft.world.inventory.EnchantmentMenu) ItemStack(net.minecraft.world.item.ItemStack) ViewableInventory(org.spongepowered.api.item.inventory.type.ViewableInventory) WanderingTrader(net.minecraft.world.entity.npc.WanderingTrader) Inventory(org.spongepowered.api.item.inventory.Inventory) NonNull(org.checkerframework.checker.nullness.qual.NonNull) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) OptionalInt(java.util.OptionalInt) Supplier(java.util.function.Supplier) TransferInventoryEvent(org.spongepowered.api.event.item.inventory.TransferInventoryEvent) ArrayList(java.util.ArrayList) ServerPlayer(net.minecraft.server.level.ServerPlayer) Container(net.minecraft.world.Container) TrackingUtil(org.spongepowered.common.event.tracking.TrackingUtil) ItemStackUtil(org.spongepowered.common.item.util.ItemStackUtil) Component(net.kyori.adventure.text.Component) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Nullable(org.checkerframework.checker.nullness.qual.Nullable) UpdateAnvilEvent(org.spongepowered.api.event.item.inventory.UpdateAnvilEvent) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Item(org.spongepowered.api.entity.Item) ContainerUtil(org.spongepowered.common.inventory.util.ContainerUtil) Slot(org.spongepowered.api.item.inventory.Slot) SpongeCommon(org.spongepowered.common.SpongeCommon) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Entity(org.spongepowered.api.entity.Entity) AnvilMenu(net.minecraft.world.inventory.AnvilMenu) TrackedInventoryBridge(org.spongepowered.common.bridge.world.inventory.container.TrackedInventoryBridge) SpongeRandomEnchantmentListBuilder(org.spongepowered.common.item.enchantment.SpongeRandomEnchantmentListBuilder) AbstractHorse(net.minecraft.world.entity.animal.horse.AbstractHorse) ChangeEntityEquipmentEvent(org.spongepowered.api.event.entity.ChangeEntityEquipmentEvent) PacketPhaseUtil(org.spongepowered.common.event.tracking.phase.packet.PacketPhaseUtil) Collections(java.util.Collections) MerchantMenu(net.minecraft.world.inventory.MerchantMenu) AbstractHorse(net.minecraft.world.entity.animal.horse.AbstractHorse) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Optional(java.util.Optional) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) OptionalInt(java.util.OptionalInt) ContainerBridge(org.spongepowered.common.bridge.world.inventory.container.ContainerBridge) SimpleMenuProvider(net.minecraft.world.SimpleMenuProvider) MenuProvider(net.minecraft.world.MenuProvider) ViewableInventory(org.spongepowered.api.item.inventory.type.ViewableInventory) SimpleMenuProvider(net.minecraft.world.SimpleMenuProvider) Merchant(net.minecraft.world.item.trading.Merchant) Villager(net.minecraft.world.entity.npc.Villager) WanderingTrader(net.minecraft.world.entity.npc.WanderingTrader) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)14 ServerPlayer (net.minecraft.server.level.ServerPlayer)5 ItemStack (net.minecraft.world.item.ItemStack)4 Inventory (org.spongepowered.api.item.inventory.Inventory)4 TextComponent (net.minecraft.network.chat.TextComponent)3 MenuProvider (net.minecraft.world.MenuProvider)3 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 ClientboundOpenScreenPacket (net.minecraft.network.protocol.game.ClientboundOpenScreenPacket)2 Player (net.minecraft.world.entity.player.Player)2 ContainerListener (net.minecraft.world.inventory.ContainerListener)2 CarriedInventory (org.spongepowered.api.item.inventory.type.CarriedInventory)2 TransactionalCaptureSupplier (org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier)2 Lens (org.spongepowered.common.inventory.lens.Lens)2 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 OptionalInt (java.util.OptionalInt)1 Supplier (java.util.function.Supplier)1