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)));
}
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)));
}
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);
}
}
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);
}
}
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;
}
Aggregations