mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-06 15:52:03 +00:00
refactor(core): 存储容器逻辑
This commit is contained in:
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
import net.momirealms.craftengine.bukkit.block.entity.BukkitBlockEntityTypes;
|
||||
import net.momirealms.craftengine.bukkit.block.entity.SimpleStorageBlockEntity;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.nms.StorageContainer;
|
||||
import net.momirealms.craftengine.bukkit.plugin.gui.BukkitInventory;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
@@ -25,9 +26,6 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.CEWorld;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -73,11 +71,9 @@ public class SimpleStorageBlockBehavior extends BukkitBlockBehavior implements E
|
||||
net.momirealms.craftengine.core.entity.player.Player player = context.getPlayer();
|
||||
BlockEntity blockEntity = world.getBlockEntityAtIfLoaded(context.getClickedPos());
|
||||
if (player != null && blockEntity instanceof SimpleStorageBlockEntity entity) {
|
||||
Player bukkitPlayer = (Player) player.platformPlayer();
|
||||
Optional.ofNullable(entity.inventory()).ifPresent(inventory -> {
|
||||
Optional.ofNullable(entity.container()).ifPresent(container -> {
|
||||
entity.onPlayerOpen(player);
|
||||
bukkitPlayer.openInventory(inventory);
|
||||
new BukkitInventory(inventory).open(player, AdventureHelper.miniMessage().deserialize(this.containerTitle, PlayerOptionalContext.of(player).tagResolvers()));
|
||||
new BukkitInventory(container).open(player, AdventureHelper.miniMessage().deserialize(this.containerTitle, PlayerOptionalContext.of(player).tagResolvers()));
|
||||
});
|
||||
}
|
||||
return InteractionResult.SUCCESS_AND_CANCEL;
|
||||
@@ -156,18 +152,15 @@ public class SimpleStorageBlockBehavior extends BukkitBlockBehavior implements E
|
||||
CEWorld ceWorld = BukkitWorldManager.instance().getWorld(bukkitWorld.getUID());
|
||||
BlockEntity blockEntity = ceWorld.getBlockEntityAtIfLoaded(pos);
|
||||
if (blockEntity instanceof SimpleStorageBlockEntity entity) {
|
||||
Inventory inventory = entity.inventory();
|
||||
if (inventory != null) {
|
||||
float signal = 0.0F;
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
ItemStack item = inventory.getItem(i);
|
||||
if (item != null) {
|
||||
signal += (float) item.getAmount() / (float) (Math.min(inventory.getMaxStackSize(), item.getMaxStackSize()));
|
||||
}
|
||||
}
|
||||
signal /= (float) inventory.getSize();
|
||||
return MiscUtils.lerpDiscrete(signal, 0, 15);
|
||||
StorageContainer container = entity.container();
|
||||
if (container == null) return 0;
|
||||
float signal = 0.0F;
|
||||
for (Object item : container.contents()) {
|
||||
if (FastNMS.INSTANCE.method$ItemStack$isEmpty(item)) continue;
|
||||
signal += (float) FastNMS.INSTANCE.field$ItemStack$count(item) / (float) (Math.min(container.maxItemStackSize(), FastNMS.INSTANCE.method$ItemStack$getMaxStackSize(item)));
|
||||
}
|
||||
signal /= (float) container.containerSize();
|
||||
return MiscUtils.lerpDiscrete(signal, 0, 15);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -183,7 +176,7 @@ public class SimpleStorageBlockBehavior extends BukkitBlockBehavior implements E
|
||||
BlockPos blockPos = LocationUtils.fromBlockPos(args[2]);
|
||||
BlockEntity blockEntity = ceWorld.getBlockEntityAtIfLoaded(blockPos);
|
||||
if (blockEntity instanceof SimpleStorageBlockEntity entity) {
|
||||
return FastNMS.INSTANCE.method$CraftInventory$getInventory(entity.inventory());
|
||||
return entity.container();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
||||
import net.momirealms.craftengine.bukkit.block.behavior.SimpleStorageBlockBehavior;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.nms.StorageContainer;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
@@ -23,8 +24,6 @@ import net.momirealms.sparrow.nbt.ListTag;
|
||||
import org.bukkit.GameEvent;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -33,7 +32,7 @@ import java.util.Optional;
|
||||
|
||||
public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
private final SimpleStorageBlockBehavior behavior;
|
||||
private final Inventory inventory;
|
||||
private final StorageContainer container;
|
||||
private double maxInteractionDistance;
|
||||
private boolean openState = false;
|
||||
|
||||
@@ -41,33 +40,31 @@ public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
super(BukkitBlockEntityTypes.SIMPLE_STORAGE, pos, blockState);
|
||||
this.behavior = super.blockState.behavior().getAs(SimpleStorageBlockBehavior.class).orElseThrow();
|
||||
BlockEntityHolder holder = new BlockEntityHolder(this);
|
||||
this.inventory = FastNMS.INSTANCE.createSimpleStorageContainer(holder, this.behavior.rows() * 9, this.behavior.canPlaceItem(), this.behavior.canTakeItem());
|
||||
holder.setInventory(this.inventory);
|
||||
this.container = FastNMS.INSTANCE.createSimpleStorageContainer(holder, this.behavior.rows() * 9, this.behavior.canPlaceItem(), this.behavior.canTakeItem());
|
||||
holder.setInventory(FastNMS.INSTANCE.constructor$CraftInventory(this.container));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveCustomData(CompoundTag tag) {
|
||||
// 保存前先把所有打开此容器的玩家界面关闭
|
||||
this.inventory.close();
|
||||
this.container.getViewers().forEach(HumanEntity::closeInventory);
|
||||
ListTag itemsTag = new ListTag();
|
||||
@Nullable ItemStack[] storageContents = this.inventory.getStorageContents();
|
||||
for (int i = 0; i < storageContents.length; i++) {
|
||||
if (storageContents[i] != null) {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
int slot = i;
|
||||
CoreReflections.instance$ItemStack$CODEC.encodeStart(MRegistryOps.SPARROW_NBT, FastNMS.INSTANCE.field$CraftItemStack$handle(storageContents[i]))
|
||||
.ifSuccess(success -> {
|
||||
CompoundTag itemTag = (CompoundTag) success;
|
||||
itemTag.putInt("slot", slot);
|
||||
itemsTag.add(itemTag);
|
||||
})
|
||||
.ifError(error -> CraftEngine.instance().logger().severe("Error while saving storage item: " + error));
|
||||
} else {
|
||||
Object nmsTag = FastNMS.INSTANCE.method$itemStack$save(FastNMS.INSTANCE.field$CraftItemStack$handle(storageContents[i]), FastNMS.INSTANCE.constructor$CompoundTag());
|
||||
CompoundTag itemTag = (CompoundTag) MRegistryOps.NBT.convertTo(MRegistryOps.SPARROW_NBT, nmsTag);
|
||||
itemTag.putInt("slot", i);
|
||||
itemsTag.add(itemTag);
|
||||
}
|
||||
List<?> items = this.container.contents();
|
||||
for (Object itemStack : items) {
|
||||
if (FastNMS.INSTANCE.method$ItemStack$isEmpty(itemStack)) continue;
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
CoreReflections.instance$ItemStack$CODEC.encodeStart(MRegistryOps.SPARROW_NBT, itemStack)
|
||||
.ifSuccess(success -> {
|
||||
CompoundTag itemTag = (CompoundTag) success;
|
||||
itemTag.putInt("slot", items.indexOf(itemStack));
|
||||
itemsTag.add(itemTag);
|
||||
})
|
||||
.ifError(error -> CraftEngine.instance().logger().severe("Error while saving storage item: " + error));
|
||||
} else {
|
||||
Object nmsTag = FastNMS.INSTANCE.method$itemStack$save(itemStack, FastNMS.INSTANCE.constructor$CompoundTag());
|
||||
CompoundTag itemTag = (CompoundTag) MRegistryOps.NBT.convertTo(MRegistryOps.SPARROW_NBT, nmsTag);
|
||||
itemTag.putInt("slot", items.indexOf(itemStack));
|
||||
itemsTag.add(itemTag);
|
||||
}
|
||||
}
|
||||
tag.put("items", itemsTag);
|
||||
@@ -76,36 +73,34 @@ public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
@Override
|
||||
public void loadCustomData(CompoundTag tag) {
|
||||
ListTag itemsTag = Optional.ofNullable(tag.getList("items")).orElseGet(ListTag::new);
|
||||
ItemStack[] storageContents = new ItemStack[this.behavior.rows() * 9];
|
||||
for (int i = 0; i < itemsTag.size(); i++) {
|
||||
CompoundTag itemTag = itemsTag.getCompound(i);
|
||||
int slot = itemTag.getInt("slot");
|
||||
if (slot < 0 || slot >= storageContents.length) {
|
||||
if (slot < 0 || slot >= this.behavior.rows() * 9) {
|
||||
continue;
|
||||
}
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
CoreReflections.instance$ItemStack$CODEC.parse(MRegistryOps.SPARROW_NBT, itemTag)
|
||||
.resultOrPartial((s) -> CraftEngine.instance().logger().severe("Tried to load invalid item: '" + itemTag + "'. " + s))
|
||||
.ifPresent(nmsStack -> storageContents[slot] = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(nmsStack));
|
||||
.ifPresent(nmsStack -> this.container.setItemStack(slot, nmsStack));
|
||||
} else {
|
||||
Object nmsTag = MRegistryOps.SPARROW_NBT.convertTo(MRegistryOps.NBT, itemTag);
|
||||
Object itemStack = FastNMS.INSTANCE.method$ItemStack$of(nmsTag);
|
||||
storageContents[slot] = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack);
|
||||
this.container.setItemStack(slot, itemStack);
|
||||
}
|
||||
}
|
||||
this.inventory.setStorageContents(storageContents);
|
||||
}
|
||||
|
||||
public Inventory inventory() {
|
||||
public StorageContainer container() {
|
||||
if (!isValid()) return null;
|
||||
return this.inventory;
|
||||
return this.container;
|
||||
}
|
||||
|
||||
public void onPlayerOpen(Player player) {
|
||||
if (!isValidContainer()) return;
|
||||
if (!player.isSpectatorMode()) {
|
||||
// 有非观察者的人,那么就不触发开启音效和事件
|
||||
if (!hasNoViewer(this.inventory.getViewers())) return;
|
||||
if (!hasNoViewer(this.container.getViewers())) return;
|
||||
this.maxInteractionDistance = Math.max(player.getCachedInteractionRange(), this.maxInteractionDistance);
|
||||
this.setOpen(player);
|
||||
FastNMS.INSTANCE.method$ScheduledTickAccess$scheduleBlockTick(super.world.world().serverWorld(), LocationUtils.toBlockPos(this.pos), BlockStateUtils.getBlockOwner(this.blockState.customBlockState().literalObject()), 5);
|
||||
@@ -116,7 +111,7 @@ public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
if (!isValidContainer()) return;
|
||||
if (!player.isSpectatorMode()) {
|
||||
// 有非观察者的人,那么就不触发关闭音效和事件
|
||||
for (HumanEntity viewer : this.inventory.getViewers()) {
|
||||
for (HumanEntity viewer : this.container.getViewers()) {
|
||||
if (viewer.getGameMode() == GameMode.SPECTATOR || viewer == player.platformPlayer()) {
|
||||
continue;
|
||||
}
|
||||
@@ -167,7 +162,7 @@ public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
}
|
||||
|
||||
private boolean isValidContainer() {
|
||||
return this.isValid() && this.inventory != null && this.behavior != null;
|
||||
return this.isValid() && this.container != null && this.behavior != null;
|
||||
}
|
||||
|
||||
public void updateOpenBlockState(boolean open) {
|
||||
@@ -181,7 +176,7 @@ public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
public void checkOpeners(Object level, Object pos, Object blockState) {
|
||||
if (!this.isValidContainer()) return;
|
||||
double maxInteractionDistance = 0d;
|
||||
List<HumanEntity> viewers = this.inventory.getViewers();
|
||||
List<HumanEntity> viewers = this.container.getViewers();
|
||||
int validViewers = 0;
|
||||
for (HumanEntity viewer : viewers) {
|
||||
if (viewer instanceof org.bukkit.entity.Player player) {
|
||||
@@ -206,13 +201,15 @@ public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
|
||||
@Override
|
||||
public void preRemove() {
|
||||
this.inventory.close();
|
||||
this.container.getViewers().forEach(HumanEntity::closeInventory);
|
||||
Vec3d pos = Vec3d.atCenterOf(this.pos);
|
||||
for (ItemStack stack : this.inventory.getContents()) {
|
||||
if (stack != null) {
|
||||
super.world.world().dropItemNaturally(pos, BukkitItemManager.instance().wrap(stack));
|
||||
}
|
||||
for (Object stack : this.container.contents()) {
|
||||
if (FastNMS.INSTANCE.method$ItemStack$isEmpty(stack)) continue;
|
||||
super.world.world().dropItemNaturally(pos, BukkitItemManager.instance().wrap(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(stack)));
|
||||
|
||||
}
|
||||
for (int i = 0; i < this.container.containerSize(); ++i) {
|
||||
this.container.setItemStack(i, CoreReflections.instance$ItemStack$EMPTY);
|
||||
}
|
||||
this.inventory.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,10 @@ import net.momirealms.craftengine.bukkit.util.ResourcePackUtils;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.pack.AbstractPackManager;
|
||||
import net.momirealms.craftengine.core.pack.host.ResourcePackDownloadData;
|
||||
import net.momirealms.craftengine.core.pack.obfuscation.ObfA;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.util.Base64Utils;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -21,6 +23,7 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -124,4 +127,9 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new String(Base64Utils.decode(ObfA.VALUES, Integer.parseInt(String.valueOf(ObfA.VALUES[71]).substring(0, 1))), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.block.entity.BlockEntityHolder;
|
||||
import net.momirealms.craftengine.bukkit.block.entity.SimpleStorageBlockEntity;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.nms.StorageContainer;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.NetworkReflections;
|
||||
@@ -87,24 +88,27 @@ public class BukkitGuiManager implements GuiManager, Listener {
|
||||
@Override
|
||||
public Inventory createInventory(Gui gui, int size) {
|
||||
CraftEngineGUIHolder holder = new CraftEngineGUIHolder(gui);
|
||||
org.bukkit.inventory.Inventory inventory = FastNMS.INSTANCE.createSimpleStorageContainer(holder, size, false, false);
|
||||
holder.holder().bindValue(inventory);
|
||||
return new BukkitInventory(inventory);
|
||||
StorageContainer container = FastNMS.INSTANCE.createSimpleStorageContainer(holder, size, false, false);
|
||||
holder.holder().bindValue(FastNMS.INSTANCE.constructor$CraftInventory(container));
|
||||
return new BukkitInventory(container);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
org.bukkit.inventory.Inventory inventory = event.getInventory();
|
||||
if (!InventoryUtils.isCustomContainer(inventory)) return;
|
||||
Object container = FastNMS.INSTANCE.method$CraftInventory$getInventory(inventory);
|
||||
if (!(container instanceof StorageContainer storageContainer)) return;
|
||||
if (!(inventory.getHolder() instanceof CraftEngineGUIHolder craftEngineGUIHolder)) {
|
||||
return;
|
||||
}
|
||||
AbstractGui gui = (AbstractGui) craftEngineGUIHolder.gui();
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (event.getClickedInventory() == player.getInventory()) {
|
||||
gui.handleInventoryClick(new BukkitClick(event, gui, new BukkitInventory(player.getInventory())));
|
||||
Object playerContainer = FastNMS.INSTANCE.method$CraftInventory$getInventory(player.getInventory());
|
||||
if (!(playerContainer instanceof StorageContainer playerStorageContainer)) return;
|
||||
gui.handleInventoryClick(new BukkitClick(event, gui, new BukkitInventory(playerStorageContainer)));
|
||||
} else if (event.getClickedInventory() == inventory) {
|
||||
gui.handleGuiClick(new BukkitClick(event, gui, new BukkitInventory(inventory)));
|
||||
gui.handleGuiClick(new BukkitClick(event, gui, new BukkitInventory(storageContainer)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.gui;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.bukkit.CraftBukkitReflections;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.nms.StorageContainer;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.NetworkReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.gui.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BukkitInventory implements Inventory {
|
||||
private final org.bukkit.inventory.Inventory inventory;
|
||||
private final StorageContainer container;
|
||||
|
||||
public BukkitInventory(org.bukkit.inventory.Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
public BukkitInventory(StorageContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,14 +23,14 @@ public class BukkitInventory implements Inventory {
|
||||
BukkitServerPlayer serverPlayer = (BukkitServerPlayer) player;
|
||||
Object nmsPlayer = serverPlayer.serverPlayer();
|
||||
try {
|
||||
Object menuType = CraftBukkitReflections.method$CraftContainer$getNotchInventoryType.invoke(null, inventory);
|
||||
int nextId = (int) CoreReflections.method$ServerPlayer$nextContainerCounter.invoke(nmsPlayer);
|
||||
Object menu = CraftBukkitReflections.constructor$CraftContainer.newInstance(inventory, nmsPlayer, nextId);
|
||||
CoreReflections.field$AbstractContainerMenu$checkReachable.set(menu, false);
|
||||
Object packet = NetworkReflections.constructor$ClientboundOpenScreenPacket.newInstance(nextId, menuType, ComponentUtils.adventureToMinecraft(title));
|
||||
int nextId = FastNMS.INSTANCE.method$ServerPlayer$nextContainerCounter(nmsPlayer);
|
||||
Object nmsTitle = ComponentUtils.adventureToMinecraft(title);
|
||||
Object menu = FastNMS.INSTANCE.createSimpleContainerMenu(this.container, nextId, nmsPlayer, nmsTitle);
|
||||
FastNMS.INSTANCE.field$AbstractContainerMenu$checkReachable(menu, false);
|
||||
Object packet = FastNMS.INSTANCE.constructor$ClientboundOpenScreenPacket(nextId, this.container.menuType(), nmsTitle);
|
||||
serverPlayer.sendPacket(packet, false);
|
||||
CoreReflections.field$Player$containerMenu.set(nmsPlayer, menu);
|
||||
CoreReflections.method$ServerPlayer$initMenu.invoke(nmsPlayer, menu);
|
||||
FastNMS.INSTANCE.field$Player$containerMenu(nmsPlayer, menu);
|
||||
FastNMS.INSTANCE.method$ServerPlayer$initMenu(nmsPlayer, menu);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to create bukkit inventory", e);
|
||||
}
|
||||
@@ -39,6 +38,6 @@ public class BukkitInventory implements Inventory {
|
||||
|
||||
@Override
|
||||
public void setItem(int index, Item<?> item) {
|
||||
this.inventory.setItem(index, item == null ? null : (ItemStack) item.getItem());
|
||||
this.container.setItemStack(index, item == null ? CoreReflections.instance$ItemStack$EMPTY : item.getLiteralObject());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user