mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-27 19:09:08 +00:00
fix(block): 修
This commit is contained in:
@@ -208,8 +208,8 @@ public class SimpleStorageBlockBehavior extends BukkitBlockBehavior implements E
|
||||
boolean canPlaceItem = true;
|
||||
boolean canTakeItem = true;
|
||||
if (hopperBehavior != null) {
|
||||
canPlaceItem = ResourceConfigUtils.getAsBoolean(hopperBehavior.getOrDefault("can-place-item", true), "can-place-item");
|
||||
canTakeItem = ResourceConfigUtils.getAsBoolean(hopperBehavior.getOrDefault("can-take-item", true), "can-take-item");
|
||||
canPlaceItem = ResourceConfigUtils.getAsBoolean(hopperBehavior.getOrDefault("allow-input", true), "allow-input");
|
||||
canTakeItem = ResourceConfigUtils.getAsBoolean(hopperBehavior.getOrDefault("allow-output", true), "allow-output");
|
||||
}
|
||||
Property<Boolean> property = (Property<Boolean>) block.getProperty("open");
|
||||
return new SimpleStorageBlockBehavior(block, title, rows, openSound, closeSound, hasAnalogOutputSignal, canPlaceItem, canTakeItem, property);
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.momirealms.craftengine.bukkit.plugin.reflection.bukkit.CraftBukkitRef
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.NetworkReflections;
|
||||
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.InventoryUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LegacyInventoryUtils;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.gui.*;
|
||||
@@ -98,11 +99,7 @@ public class BukkitGuiManager implements GuiManager, Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
org.bukkit.inventory.Inventory inventory = event.getInventory();
|
||||
Object container = FastNMS.INSTANCE.method$CraftInventory$getInventory(inventory);
|
||||
if (!CraftBukkitReflections.clazz$MinecraftInventory.isInstance(container)
|
||||
|| !container.getClass().getSimpleName().equals("CraftEngineWorldlyContainer")) {
|
||||
return;
|
||||
}
|
||||
if (!InventoryUtils.isCustomContainer(inventory)) return;
|
||||
if (!(inventory.getHolder() instanceof CraftEngineGUIHolder craftEngineGUIHolder)) {
|
||||
return;
|
||||
}
|
||||
@@ -118,11 +115,7 @@ public class BukkitGuiManager implements GuiManager, Listener {
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||
public void onInventoryDrag(InventoryDragEvent event) {
|
||||
org.bukkit.inventory.Inventory inventory = event.getInventory();
|
||||
Object container = FastNMS.INSTANCE.method$CraftInventory$getInventory(inventory);
|
||||
if (!CraftBukkitReflections.clazz$MinecraftInventory.isInstance(container)
|
||||
|| !container.getClass().getSimpleName().equals("CraftEngineWorldlyContainer")) {
|
||||
return;
|
||||
}
|
||||
if (!InventoryUtils.isCustomContainer(inventory)) return;
|
||||
if (!(inventory.getHolder() instanceof CraftEngineGUIHolder)) {
|
||||
return;
|
||||
}
|
||||
@@ -138,11 +131,7 @@ public class BukkitGuiManager implements GuiManager, Listener {
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
org.bukkit.inventory.Inventory inventory = event.getInventory();
|
||||
Object container = FastNMS.INSTANCE.method$CraftInventory$getInventory(inventory);
|
||||
if (!CraftBukkitReflections.clazz$MinecraftInventory.isInstance(container)
|
||||
|| !container.getClass().getSimpleName().equals("CraftEngineWorldlyContainer")) {
|
||||
return;
|
||||
}
|
||||
if (!InventoryUtils.isCustomContainer(inventory)) return;
|
||||
if (!(inventory.getHolder() instanceof BlockEntityHolder holder)) {
|
||||
return;
|
||||
}
|
||||
@@ -155,11 +144,7 @@ public class BukkitGuiManager implements GuiManager, Listener {
|
||||
public void onInventoryClose(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
org.bukkit.inventory.Inventory inventory = player.getInventory();
|
||||
Object container = FastNMS.INSTANCE.method$CraftInventory$getInventory(inventory);
|
||||
if (!CraftBukkitReflections.clazz$MinecraftInventory.isInstance(container)
|
||||
|| !container.getClass().getSimpleName().equals("CraftEngineWorldlyContainer")) {
|
||||
return;
|
||||
}
|
||||
if (!InventoryUtils.isCustomContainer(inventory)) return;
|
||||
if (!(inventory.getHolder() instanceof BlockEntityHolder holder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -497,11 +497,7 @@ public class BukkitServerPlayer extends Player {
|
||||
|
||||
private void updateGUI() {
|
||||
org.bukkit.inventory.Inventory top = !VersionHelper.isOrAbove1_21() ? LegacyInventoryUtils.getTopInventory(platformPlayer()) : platformPlayer().getOpenInventory().getTopInventory();
|
||||
Object container = FastNMS.INSTANCE.method$CraftInventory$getInventory(top);
|
||||
if (!CraftBukkitReflections.clazz$MinecraftInventory.isInstance(container)
|
||||
|| !container.getClass().getSimpleName().equals("CraftEngineWorldlyContainer")) {
|
||||
return;
|
||||
}
|
||||
if (!InventoryUtils.isCustomContainer(top)) return;
|
||||
if (top.getHolder() instanceof CraftEngineGUIHolder holder) {
|
||||
holder.gui().onTimer();
|
||||
} else if (top.getHolder() instanceof BlockEntityHolder holder) {
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.nms.StorageContainer;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.bukkit.CraftBukkitReflections;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
@@ -49,4 +53,11 @@ public final class InventoryUtils {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean isCustomContainer(Inventory inventory) {
|
||||
if (inventory == null) return false;
|
||||
Object container = FastNMS.INSTANCE.method$CraftInventory$getInventory(inventory);
|
||||
if (container == null) return false;
|
||||
return CraftBukkitReflections.clazz$MinecraftInventory.isInstance(container) || StorageContainer.isInstance(container);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ items:
|
||||
open: minecraft:block.iron_trapdoor.open
|
||||
close: minecraft:block.iron_trapdoor.close
|
||||
hopper-behavior:
|
||||
can-place-item: true
|
||||
can-take-item: false
|
||||
allow-input: true
|
||||
allow-output: false
|
||||
states:
|
||||
properties:
|
||||
facing:
|
||||
|
||||
Reference in New Issue
Block a user