mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-27 19:09:08 +00:00
添加可覆写lore,增强物品数据读取逻辑
This commit is contained in:
@@ -47,6 +47,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.block.BlockType;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -885,4 +886,21 @@ public final class BukkitBlockManager extends AbstractBlockManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBlockRegistryId(Key id) {
|
||||
Object block = FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.BLOCK, KeyUtils.toResourceLocation(id));
|
||||
return FastNMS.INSTANCE.method$IdMap$getId(MBuiltInRegistries.BLOCK, block).orElseThrow(() -> new IllegalStateException("Block " + id + " not found"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVanillaBlock(Key id) {
|
||||
if (!id.namespace().equals("minecraft")) {
|
||||
return false;
|
||||
}
|
||||
if (id.value().equals("air")) {
|
||||
return true;
|
||||
}
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.BLOCK, KeyUtils.toResourceLocation(id)) != MBlocks.AIR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,11 @@ import net.momirealms.craftengine.bukkit.util.ItemStackUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ComponentItemWrapper implements ItemWrapper<ItemStack> {
|
||||
@@ -104,6 +106,18 @@ public class ComponentItemWrapper implements ItemWrapper<ItemStack> {
|
||||
return FastNMS.INSTANCE.method$ItemStack$hasComponent(getLiteralObject(), ensureDataComponentType(type));
|
||||
}
|
||||
|
||||
public boolean hasNonDefaultComponent(Object type) {
|
||||
if (VersionHelper.isOrAbove1_21_4()) {
|
||||
return FastNMS.INSTANCE.method$ItemStack$hasNonDefaultComponent(getLiteralObject(), ensureDataComponentType(type));
|
||||
} else {
|
||||
Object item = FastNMS.INSTANCE.method$ItemStack$getItem(this.getLiteralObject());
|
||||
Object componentMap = FastNMS.INSTANCE.method$Item$components(item);
|
||||
Object componentType = ensureDataComponentType(type);
|
||||
Object defaultComponent = FastNMS.INSTANCE.method$DataComponentMap$get(componentMap, componentType);
|
||||
return !Objects.equals(defaultComponent, getComponentExact(componentType));
|
||||
}
|
||||
}
|
||||
|
||||
public void setComponentExact(Object type, final Object value) {
|
||||
FastNMS.INSTANCE.method$ItemStack$setComponent(this.getLiteralObject(), ensureDataComponentType(type), value);
|
||||
}
|
||||
|
||||
@@ -165,6 +165,11 @@ public abstract class BukkitItemFactory<W extends ItemWrapper<ItemStack>> extend
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasNonDefaultComponent(W item, Object type) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setComponent(W item, Object type, Object value) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
|
||||
@@ -267,6 +267,11 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
|
||||
return item.hasComponent(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasNonDefaultComponent(ComponentItemWrapper item, Object type) {
|
||||
return item.hasNonDefaultComponent(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeComponent(ComponentItemWrapper item, Object type) {
|
||||
item.removeComponent(type);
|
||||
|
||||
@@ -123,7 +123,7 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
@Override
|
||||
public void onPluginLoad() {
|
||||
if (super.blockManager == null) {
|
||||
injectRegistries();
|
||||
this.injectRegistries();
|
||||
}
|
||||
try {
|
||||
WorldStorageInjector.init();
|
||||
|
||||
Reference in New Issue
Block a user