use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project Mohist by MohistMC.
the class CraftHumanEntity method openInventory.
@Override
public InventoryView openInventory(Inventory inventory) {
if (!(getHandle() instanceof ServerPlayer))
return null;
ServerPlayer player = (ServerPlayer) getHandle();
AbstractContainerMenu formerContainer = getHandle().containerMenu;
MenuProvider iinventory = null;
if (inventory instanceof CraftInventoryDoubleChest) {
iinventory = ((CraftInventoryDoubleChest) inventory).tile;
} else if (inventory instanceof CraftInventoryLectern) {
iinventory = ((CraftInventoryLectern) inventory).tile;
} else if (inventory instanceof CraftInventory) {
CraftInventory craft = (CraftInventory) inventory;
if (craft.getInventory() instanceof MenuProvider) {
iinventory = (MenuProvider) craft.getInventory();
}
}
if (iinventory instanceof MenuProvider) {
if (iinventory instanceof BlockEntity) {
BlockEntity te = (BlockEntity) iinventory;
if (!te.hasLevel()) {
te.setLevel(getHandle().level);
}
}
}
MenuType<?> container = CraftContainer.getNotchInventoryType(inventory);
if (iinventory instanceof MenuProvider) {
getHandle().openMenu(iinventory);
} else {
openCustomInventory(inventory, player, container);
}
if (getHandle().containerMenu == formerContainer) {
return null;
}
getHandle().containerMenu.checkReachable = false;
return getHandle().containerMenu.getBukkitView();
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project Magma by magmafoundation.
the class CraftChest method getInventory.
@Override
public Inventory getInventory() {
CraftInventory inventory = (CraftInventory) this.getBlockInventory();
if (!isPlaced()) {
return inventory;
}
// The logic here is basically identical to the logic in BlockChest.interact
int x = this.getX();
int y = this.getY();
int z = this.getZ();
CraftWorld world = (CraftWorld) this.getWorld();
int id;
if (world.getBlockTypeIdAt(x, y, z) == Material.CHEST.getId()) {
id = Material.CHEST.getId();
} else if (world.getBlockTypeIdAt(x, y, z) == Material.TRAPPED_CHEST.getId()) {
id = Material.TRAPPED_CHEST.getId();
} else {
throw new IllegalStateException("CraftChest is not a chest but is instead " + world.getBlockAt(x, y, z));
}
if (world.getBlockTypeIdAt(x - 1, y, z) == id) {
CraftInventory left = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x - 1, y, z)));
inventory = new CraftInventoryDoubleChest(left, inventory);
}
if (world.getBlockTypeIdAt(x + 1, y, z) == id) {
CraftInventory right = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x + 1, y, z)));
inventory = new CraftInventoryDoubleChest(inventory, right);
}
if (world.getBlockTypeIdAt(x, y, z - 1) == id) {
CraftInventory left = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x, y, z - 1)));
inventory = new CraftInventoryDoubleChest(left, inventory);
}
if (world.getBlockTypeIdAt(x, y, z + 1) == id) {
CraftInventory right = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x, y, z + 1)));
inventory = new CraftInventoryDoubleChest(inventory, right);
}
return inventory;
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project Magma by magmafoundation.
the class CraftContainer method getCanCraft.
@Override
public boolean getCanCraft(EntityPlayer entityhuman) {
if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) {
return true;
}
// If the window type has changed for some reason, update the player
// This method will be called every tick or something, so it's
// as good a place as any to put something like this.
boolean typeChanged = (cachedType != view.getType());
cachedType = view.getType();
cachedTitle = view.getTitle();
if (view.getPlayer() instanceof CraftPlayer) {
CraftPlayer player = (CraftPlayer) view.getPlayer();
String type = getNotchInventoryType(cachedType);
IInventory top = ((CraftInventory) view.getTopInventory()).getInventory();
InventoryPlayer bottom = (InventoryPlayer) ((CraftInventory) view.getBottomInventory()).getInventory();
this.inventoryItemStacks.clear();
this.inventorySlots.clear();
if (typeChanged) {
setupSlots(top, bottom, player.getHandle());
}
int size = getSize();
player.getHandle().connection.sendPacket(new SPacketOpenWindow(this.windowId, type, new TextComponentString(cachedTitle), size));
player.updateInventory();
}
return true;
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project Magma-1.16.x by magmafoundation.
the class CraftHumanEntity method openInventory.
@Override
public InventoryView openInventory(Inventory inventory) {
if (!(getHandle() instanceof ServerPlayerEntity))
return null;
ServerPlayerEntity player = (ServerPlayerEntity) getHandle();
Container formerContainer = getHandle().containerMenu;
INamedContainerProvider iinventory = null;
if (inventory instanceof CraftInventoryDoubleChest) {
iinventory = ((CraftInventoryDoubleChest) inventory).tile;
} else if (inventory instanceof CraftInventory) {
CraftInventory craft = (CraftInventory) inventory;
if (craft.getInventory() instanceof INamedContainerProvider) {
iinventory = (INamedContainerProvider) craft.getInventory();
}
}
if (iinventory instanceof INamedContainerProvider) {
if (iinventory instanceof TileEntity) {
TileEntity te = (TileEntity) iinventory;
if (!te.hasLevel()) {
te.setLevelAndPosition(getHandle().level, getHandle().blockPosition());
}
}
}
ContainerType<?> container = CraftContainer.getNotchInventoryType(inventory);
if (iinventory instanceof LockableTileEntity) {
getHandle().openMenu(iinventory);
} else {
openCustomInventory(inventory, player, container);
}
if (getHandle().containerMenu == formerContainer) {
return null;
}
getHandle().containerMenu.checkReachable = false;
return getHandle().containerMenu.getBukkitView();
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project LoliServer by Loli-Server.
the class CraftLootTable method fillInventory.
@Override
public void fillInventory(Inventory inventory, Random random, LootContext context) {
net.minecraft.loot.LootContext nmsContext = convertContext(context);
CraftInventory craftInventory = (CraftInventory) inventory;
IInventory handle = craftInventory.getInventory();
// TODO: When events are added, call event here w/ custom reason?
getHandle().fill(handle, nmsContext);
}
Aggregations