9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

修改1.20.1-1.20.4nbt实现

This commit is contained in:
XiaoMoMi
2025-06-29 21:13:46 +08:00
parent 4a2d4c76c7
commit 997890ca38
38 changed files with 153 additions and 235 deletions

View File

@@ -39,7 +39,6 @@ This project draws inspiration and refers to some implementations from the follo
### Core Dependencies ### Core Dependencies
The implementation relies on these fundamental libraries: The implementation relies on these fundamental libraries:
+ [cloud-minecraft](https://github.com/Incendo/cloud-minecraft) + [cloud-minecraft](https://github.com/Incendo/cloud-minecraft)
+ [rtag](https://github.com/saicone/rtag)
+ [adventure](https://github.com/KyoriPowered/adventure) + [adventure](https://github.com/KyoriPowered/adventure)
+ [byte-buddy](https://github.com/raphw/byte-buddy) + [byte-buddy](https://github.com/raphw/byte-buddy)
@@ -63,7 +62,7 @@ The code you contribute will be open-sourced under the GPLv3 license. If you pre
### 💖 Support the Developer ### 💖 Support the Developer
Help sustain CraftEngine's development by going Premium! Help sustain CraftEngine's development by going Premium!
- **Polymart**: [None] - **Polymart**: [Support via Polymart](https://polymart.org/product/7624/craftengine)
- **BuiltByBit**: [None] - **BuiltByBit**: [None]
- **Afdian**: [Support via Afdian](https://afdian.com/@xiaomomi/) - **Afdian**: [Support via Afdian](https://afdian.com/@xiaomomi/)
@@ -76,7 +75,7 @@ repositories {
``` ```
```kotlin ```kotlin
dependencies { dependencies {
compileOnly("net.momirealms:craft-engine-core:0.0.57") compileOnly("net.momirealms:craft-engine-core:0.0.59")
compileOnly("net.momirealms:craft-engine-bukkit:0.0.57") compileOnly("net.momirealms:craft-engine-bukkit:0.0.59")
} }
``` ```

View File

@@ -46,9 +46,6 @@ dependencies {
compileOnly("org.incendo:cloud-paper:${rootProject.properties["cloud_paper_version"]}") compileOnly("org.incendo:cloud-paper:${rootProject.properties["cloud_paper_version"]}")
// YAML // YAML
compileOnly(files("${rootProject.rootDir}/libs/boosted-yaml-${rootProject.properties["boosted_yaml_version"]}.jar")) compileOnly(files("${rootProject.rootDir}/libs/boosted-yaml-${rootProject.properties["boosted_yaml_version"]}.jar"))
// Item Tag
compileOnly("com.saicone.rtag:rtag:${rootProject.properties["rtag_version"]}")
compileOnly("com.saicone.rtag:rtag-item:${rootProject.properties["rtag_version"]}")
// Adventure // Adventure
compileOnly("net.kyori:adventure-api:${rootProject.properties["adventure_bundle_version"]}") compileOnly("net.kyori:adventure-api:${rootProject.properties["adventure_bundle_version"]}")
compileOnly("net.kyori:adventure-text-minimessage:${rootProject.properties["adventure_bundle_version"]}") compileOnly("net.kyori:adventure-text-minimessage:${rootProject.properties["adventure_bundle_version"]}")
@@ -89,7 +86,6 @@ tasks {
relocate("net.kyori", "net.momirealms.craftengine.libraries") relocate("net.kyori", "net.momirealms.craftengine.libraries")
relocate("net.momirealms.sparrow.nbt", "net.momirealms.craftengine.libraries.nbt") relocate("net.momirealms.sparrow.nbt", "net.momirealms.craftengine.libraries.nbt")
relocate("net.momirealms.antigrieflib", "net.momirealms.craftengine.libraries.antigrieflib") relocate("net.momirealms.antigrieflib", "net.momirealms.craftengine.libraries.antigrieflib")
relocate("com.saicone.rtag", "net.momirealms.craftengine.libraries.tag")
relocate("org.incendo", "net.momirealms.craftengine.libraries") relocate("org.incendo", "net.momirealms.craftengine.libraries")
relocate("dev.dejvokep", "net.momirealms.craftengine.libraries") relocate("dev.dejvokep", "net.momirealms.craftengine.libraries")
relocate("org.bstats", "net.momirealms.craftengine.libraries.bstats") relocate("org.bstats", "net.momirealms.craftengine.libraries.bstats")

View File

@@ -55,10 +55,9 @@ public class ExprItemCustomItemID extends SimplePropertyExpression<Object, Strin
Item<ItemStack> item1 = BukkitItemManager.instance().wrap(itemStack); Item<ItemStack> item1 = BukkitItemManager.instance().wrap(itemStack);
Item<ItemStack> item2 = BukkitItemManager.instance().createWrappedItem(id, null); Item<ItemStack> item2 = BukkitItemManager.instance().createWrappedItem(id, null);
item1.merge(item2); item1.merge(item2);
item1.load();
} else if (item instanceof ItemType itemType) { } else if (item instanceof ItemType itemType) {
Item<ItemStack> item2 = BukkitItemManager.instance().createWrappedItem(id, null); Item<ItemStack> item2 = BukkitItemManager.instance().createWrappedItem(id, null);
itemType.setItemMeta(item2.load().getItemMeta()); itemType.setItemMeta(item2.getItem().getItemMeta());
} }
} }
} }

View File

@@ -21,7 +21,6 @@ dependencies {
implementation(project(":bukkit:compatibility:legacy")) implementation(project(":bukkit:compatibility:legacy"))
implementation(project(":common-files")) implementation(project(":common-files"))
implementation("com.saicone.rtag:rtag-item:${rootProject.properties["rtag_version"]}")
implementation("net.momirealms:sparrow-util:${rootProject.properties["sparrow_util_version"]}") implementation("net.momirealms:sparrow-util:${rootProject.properties["sparrow_util_version"]}")
implementation("net.momirealms:antigrieflib:${rootProject.properties["anti_grief_version"]}") implementation("net.momirealms:antigrieflib:${rootProject.properties["anti_grief_version"]}")
implementation("net.momirealms:craft-engine-nms-helper:${rootProject.properties["nms_helper_version"]}") implementation("net.momirealms:craft-engine-nms-helper:${rootProject.properties["nms_helper_version"]}")
@@ -48,7 +47,7 @@ bukkit {
name = "CraftEngine" name = "CraftEngine"
apiVersion = "1.20" apiVersion = "1.20"
authors = listOf("XiaoMoMi") authors = listOf("XiaoMoMi")
contributors = listOf("jhqwqmc", "iqtesterrr") contributors = listOf("jhqwqmc", "iqtesterrr", "WhiteProject1", "Catnies", "xiaozhangup", "TamashiiMon")
softDepend = listOf("PlaceholderAPI", "WorldEdit", "FastAsyncWorldEdit", "Skript") softDepend = listOf("PlaceholderAPI", "WorldEdit", "FastAsyncWorldEdit", "Skript")
foliaSupported = true foliaSupported = true
} }
@@ -64,7 +63,6 @@ tasks {
relocate("net.kyori", "net.momirealms.craftengine.libraries") relocate("net.kyori", "net.momirealms.craftengine.libraries")
relocate("net.momirealms.sparrow.nbt", "net.momirealms.craftengine.libraries.nbt") relocate("net.momirealms.sparrow.nbt", "net.momirealms.craftengine.libraries.nbt")
relocate("net.momirealms.antigrieflib", "net.momirealms.craftengine.libraries.antigrieflib") relocate("net.momirealms.antigrieflib", "net.momirealms.craftengine.libraries.antigrieflib")
relocate("com.saicone.rtag", "net.momirealms.craftengine.libraries.tag")
relocate("org.incendo", "net.momirealms.craftengine.libraries") relocate("org.incendo", "net.momirealms.craftengine.libraries")
relocate("dev.dejvokep", "net.momirealms.craftengine.libraries") relocate("dev.dejvokep", "net.momirealms.craftengine.libraries")
relocate("org.bstats", "net.momirealms.craftengine.libraries.bstats") relocate("org.bstats", "net.momirealms.craftengine.libraries.bstats")

View File

@@ -23,7 +23,6 @@ dependencies {
implementation(project(":bukkit:compatibility:legacy")) implementation(project(":bukkit:compatibility:legacy"))
implementation(project(":common-files")) implementation(project(":common-files"))
implementation("com.saicone.rtag:rtag-item:${rootProject.properties["rtag_version"]}")
implementation("net.momirealms:sparrow-util:${rootProject.properties["sparrow_util_version"]}") implementation("net.momirealms:sparrow-util:${rootProject.properties["sparrow_util_version"]}")
implementation("net.momirealms:antigrieflib:${rootProject.properties["anti_grief_version"]}") implementation("net.momirealms:antigrieflib:${rootProject.properties["anti_grief_version"]}")
implementation("net.momirealms:craft-engine-nms-helper-mojmap:${rootProject.properties["nms_helper_version"]}") implementation("net.momirealms:craft-engine-nms-helper-mojmap:${rootProject.properties["nms_helper_version"]}")
@@ -51,7 +50,7 @@ paper {
name = "CraftEngine" name = "CraftEngine"
apiVersion = "1.20" apiVersion = "1.20"
authors = listOf("XiaoMoMi") authors = listOf("XiaoMoMi")
contributors = listOf("jhqwqmc", "iqtesterrr") contributors = listOf("jhqwqmc", "iqtesterrr", "WhiteProject1", "Catnies", "xiaozhangup", "TamashiiMon")
foliaSupported = true foliaSupported = true
serverDependencies { serverDependencies {
register("PlaceholderAPI") { register("PlaceholderAPI") {
@@ -137,7 +136,6 @@ tasks {
relocate("net.kyori", "net.momirealms.craftengine.libraries") relocate("net.kyori", "net.momirealms.craftengine.libraries")
relocate("net.momirealms.sparrow.nbt", "net.momirealms.craftengine.libraries.nbt") relocate("net.momirealms.sparrow.nbt", "net.momirealms.craftengine.libraries.nbt")
relocate("net.momirealms.antigrieflib", "net.momirealms.craftengine.libraries.antigrieflib") relocate("net.momirealms.antigrieflib", "net.momirealms.craftengine.libraries.antigrieflib")
relocate("com.saicone.rtag", "net.momirealms.craftengine.libraries.tag")
relocate("org.incendo", "net.momirealms.craftengine.libraries") relocate("org.incendo", "net.momirealms.craftengine.libraries")
relocate("dev.dejvokep", "net.momirealms.craftengine.libraries") relocate("dev.dejvokep", "net.momirealms.craftengine.libraries")
relocate("org.bstats", "net.momirealms.craftengine.libraries.bstats") relocate("org.bstats", "net.momirealms.craftengine.libraries.bstats")

View File

@@ -33,7 +33,6 @@ import net.momirealms.craftengine.core.pack.LoadingSequence;
import net.momirealms.craftengine.core.pack.Pack; import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.pack.ResourceLocation; import net.momirealms.craftengine.core.pack.ResourceLocation;
import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration; import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.config.ConfigParser; import net.momirealms.craftengine.core.plugin.config.ConfigParser;
import net.momirealms.craftengine.core.plugin.config.StringKeyConstructor; import net.momirealms.craftengine.core.plugin.config.StringKeyConstructor;
import net.momirealms.craftengine.core.plugin.context.event.EventFunctions; import net.momirealms.craftengine.core.plugin.context.event.EventFunctions;

View File

@@ -63,7 +63,6 @@ public class BukkitFurnitureElement extends AbstractFurnitureElement {
} else { } else {
if (color != null) { if (color != null) {
item.dyedColor(color); item.dyedColor(color);
item.load();
} }
} }
ItemDisplayEntityData.DisplayedItem.addEntityDataIfNotDefaultValue(item.getLiteralObject(), cachedValues); ItemDisplayEntityData.DisplayedItem.addEntityDataIfNotDefaultValue(item.getLiteralObject(), cachedValues);

View File

@@ -153,7 +153,7 @@ public class BukkitFontManager extends AbstractFontManager implements Listener {
if (replaceProcessResult.changed()) { if (replaceProcessResult.changed()) {
Item<ItemStack> wrapped = this.plugin.itemManager().wrap(result); Item<ItemStack> wrapped = this.plugin.itemManager().wrap(result);
wrapped.customNameJson(AdventureHelper.componentToJson(replaceProcessResult.newText())); wrapped.customNameJson(AdventureHelper.componentToJson(replaceProcessResult.newText()));
event.setResult(wrapped.load()); event.setResult(wrapped.getItem());
} }
} }

View File

@@ -38,7 +38,7 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
for (ItemDataModifier<ItemStack> modifier : this.modifiers) { for (ItemDataModifier<ItemStack> modifier : this.modifiers) {
modifier.apply(wrapped, context); modifier.apply(wrapped, context);
} }
return wrapped.load(); return wrapped.getItem();
} }
@Override @Override
@@ -48,7 +48,7 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
for (ItemDataModifier<ItemStack> modifier : dataModifiers()) { for (ItemDataModifier<ItemStack> modifier : dataModifiers()) {
modifier.apply(wrapped, context); modifier.apply(wrapped, context);
} }
return BukkitCraftEngine.instance().itemManager().wrap(wrapped.load()); return BukkitCraftEngine.instance().itemManager().wrap(wrapped.getItem());
} }
public Object clientItem() { public Object clientItem() {

View File

@@ -83,7 +83,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
try { try {
Item<ItemStack> wrapped = wrap(itemStack); Item<ItemStack> wrapped = wrap(itemStack);
if (wrapped == null) return Optional.empty(); if (wrapped == null) return Optional.empty();
return this.networkItemHandler.s2c(wrapped, player).map(Item::load); return this.networkItemHandler.s2c(wrapped, player).map(Item::getItem);
} catch (Throwable e) { } catch (Throwable e) {
if (Config.debug()) { if (Config.debug()) {
this.plugin.logger().warn("Failed to handle s2c items.", e); this.plugin.logger().warn("Failed to handle s2c items.", e);
@@ -96,7 +96,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
try { try {
Item<ItemStack> wrapped = wrap(itemStack); Item<ItemStack> wrapped = wrap(itemStack);
if (wrapped == null) return Optional.empty(); if (wrapped == null) return Optional.empty();
return this.networkItemHandler.c2s(wrapped).map(Item::load); return this.networkItemHandler.c2s(wrapped).map(Item::getItem);
} catch (Throwable e) { } catch (Throwable e) {
if (Config.debug()) { if (Config.debug()) {
this.plugin.logger().warn("Failed to handle c2s items.", e); this.plugin.logger().warn("Failed to handle c2s items.", e);

View File

@@ -153,11 +153,6 @@ public class ComponentItemWrapper implements ItemWrapper<ItemStack> {
return this.item; return this.item;
} }
@Override
public ItemStack load() {
return this.item;
}
@Override @Override
public Object getLiteralObject() { public Object getLiteralObject() {
return this.handle; return this.handle;

View File

@@ -1,36 +1,60 @@
package net.momirealms.craftengine.bukkit.item; package net.momirealms.craftengine.bukkit.item;
import com.saicone.rtag.RtagItem; import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
import net.momirealms.craftengine.bukkit.util.ItemUtils;
import net.momirealms.craftengine.core.item.ItemWrapper; import net.momirealms.craftengine.core.item.ItemWrapper;
import net.momirealms.sparrow.nbt.Tag; import net.momirealms.sparrow.nbt.Tag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class LegacyItemWrapper implements ItemWrapper<ItemStack> { public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
private final RtagItem rtagItem; private final Object nmsStack;
private final ItemStack itemStack;
public LegacyItemWrapper(RtagItem rtagItem) { public LegacyItemWrapper(ItemStack item) {
this.rtagItem = rtagItem; this.itemStack = ItemUtils.ensureCraftItemStack(item);
this.nmsStack = FastNMS.INSTANCE.field$CraftItemStack$handle(this.itemStack);
} }
public boolean setTag(Object value, Object... path) { public boolean setTag(Object value, Object... path) {
Object finalNMSTag;
if (value instanceof Tag tag) { if (value instanceof Tag tag) {
return this.rtagItem.set(MRegistryOps.SPARROW_NBT.convertTo(MRegistryOps.NBT, tag), path); finalNMSTag = MRegistryOps.SPARROW_NBT.convertTo(MRegistryOps.NBT, tag);
} else { } else {
return this.rtagItem.set(value, path); finalNMSTag = MRegistryOps.JAVA.convertTo(MRegistryOps.NBT, value);
}
}
public boolean add(Object value, Object... path) {
if (value instanceof Tag tag) {
return this.rtagItem.add(MRegistryOps.SPARROW_NBT.convertTo(MRegistryOps.NBT, tag), path);
} else {
return this.rtagItem.add(value, path);
} }
Object currentTag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(this.nmsStack);
if (path == null || path.length == 0) {
if (CoreReflections.clazz$CompoundTag.isInstance(finalNMSTag)) {
FastNMS.INSTANCE.method$ItemStack$setTag(this.nmsStack, finalNMSTag);
return true;
}
return false;
}
for (int i = 0; i < path.length - 1; i++) {
Object pathSegment = path[i];
if (pathSegment == null) return false;
Object childTag = FastNMS.INSTANCE.method$CompoundTag$get(currentTag, pathSegment.toString());
if (!CoreReflections.clazz$CompoundTag.isInstance(childTag)) {
childTag = FastNMS.INSTANCE.constructor$CompoundTag();
FastNMS.INSTANCE.method$CompoundTag$put(currentTag, pathSegment.toString(), childTag);
}
currentTag = childTag;
}
String finalKey = path[path.length - 1].toString();
FastNMS.INSTANCE.method$CompoundTag$put(currentTag, finalKey, finalNMSTag);
return true;
} }
@SuppressWarnings("unchecked")
public <V> V getJavaTag(Object... path) { public <V> V getJavaTag(Object... path) {
return this.rtagItem.get(path); Object tag = getExactTag(path);
if (tag == null) return null;
return (V) MRegistryOps.NBT.convertTo(MRegistryOps.JAVA, tag);
} }
public Tag getNBTTag(Object... path) { public Tag getNBTTag(Object... path) {
@@ -49,41 +73,73 @@ public class LegacyItemWrapper implements ItemWrapper<ItemStack> {
} }
public Object getExactTag(Object... path) { public Object getExactTag(Object... path) {
return this.rtagItem.getExact(path); Object compoundTag = FastNMS.INSTANCE.method$ItemStack$getTag(this.nmsStack);
if (compoundTag == null) return null;
Object currentTag = compoundTag;
for (int i = 0; i < path.length; i++) {
Object pathSegment = path[i];
if (pathSegment == null) return null;
currentTag = FastNMS.INSTANCE.method$CompoundTag$get(currentTag, path[i].toString());
if (currentTag == null) return null;
if (i == path.length - 1) {
return currentTag;
}
if (!CoreReflections.clazz$CompoundTag.isInstance(currentTag)) {
return null;
}
}
return null;
} }
public boolean remove(Object... path) { public boolean remove(Object... path) {
return this.rtagItem.remove(path); Object compoundTag = FastNMS.INSTANCE.method$ItemStack$getTag(this.nmsStack);
if (compoundTag == null || path == null || path.length == 0) return false;
if (path.length == 1) {
String key = path[0].toString();
if (FastNMS.INSTANCE.method$CompoundTag$get(compoundTag, key) != null) {
FastNMS.INSTANCE.method$CompoundTag$remove(compoundTag, key);
return true;
}
}
Object currentTag = compoundTag;
for (int i = 0; i < path.length - 1; i++) {
Object pathSegment = path[i];
if (pathSegment == null) return false;
currentTag = FastNMS.INSTANCE.method$CompoundTag$get(currentTag, path[i].toString());
if (!CoreReflections.clazz$CompoundTag.isInstance(currentTag)) {
return false;
}
}
String finalKey = path[path.length - 1].toString();
if (FastNMS.INSTANCE.method$CompoundTag$get(currentTag, finalKey) != null) {
FastNMS.INSTANCE.method$CompoundTag$remove(currentTag, finalKey);
return true;
}
return false;
} }
public boolean hasTag(Object... path) { public boolean hasTag(Object... path) {
return this.rtagItem.hasTag(path); return getExactTag(path) != null;
}
public void update() {
this.rtagItem.update();
}
@Override
public ItemStack load() {
return this.rtagItem.load();
} }
@Override @Override
public ItemStack getItem() { public ItemStack getItem() {
return this.rtagItem.getItem(); return this.itemStack;
} }
@Override @Override
public Object getLiteralObject() { public Object getLiteralObject() {
return this.rtagItem.getLiteralObject(); return this.nmsStack;
} }
@Override @Override
public ItemWrapper<ItemStack> copyWithCount(int count) { public ItemWrapper<ItemStack> copyWithCount(int count) {
ItemStack copied = this.rtagItem.loadCopy(); ItemStack copied = this.itemStack.clone();
copied.setAmount(count); copied.setAmount(count);
return new LegacyItemWrapper(new RtagItem(copied)); return new LegacyItemWrapper(copied);
} }
@Override @Override

View File

@@ -157,7 +157,6 @@ public class BlockItemBehavior extends BlockBoundItemBehavior {
if (!player.isCreativeMode()) { if (!player.isCreativeMode()) {
Item<?> item = context.getItem(); Item<?> item = context.getItem();
item.count(item.count() - 1); item.count(item.count() - 1);
item.load();
} }
block.setPlacedBy(context, blockStateToPlace); block.setPlacedBy(context, blockStateToPlace);

View File

@@ -158,7 +158,6 @@ public class FurnitureItemBehavior extends ItemBehavior {
if (!player.isCreativeMode()) { if (!player.isCreativeMode()) {
item.count(item.count() - 1); item.count(item.count() - 1);
item.load();
} }
context.getLevel().playBlockSound(finalPlacePosition, customFurniture.settings().sounds().placeSound()); context.getLevel().playBlockSound(finalPlacePosition, customFurniture.settings().sounds().placeSound());

View File

@@ -69,11 +69,6 @@ public abstract class BukkitItemFactory<W extends ItemWrapper<ItemStack>> extend
return customId(item).orElse(vanillaId(item)); return customId(item).orElse(vanillaId(item));
} }
@Override
protected ItemStack load(W item) {
return item.load();
}
@Override @Override
protected ItemStack getItem(W item) { protected ItemStack getItem(W item) {
return item.getItem(); return item.getItem();

View File

@@ -52,8 +52,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
for (int i = 0; i < path.length; i++) { for (int i = 0; i < path.length; i++) {
Object pathSegment = path[i]; Object pathSegment = path[i];
if (pathSegment == null) return null; if (pathSegment == null) return null;
String key = pathSegment.toString(); currentObj = ((Map<String, Object>) currentObj).get(pathSegment.toString());
currentObj = ((Map<String, Object>) currentObj).get(key);
if (currentObj == null) return null; if (currentObj == null) return null;
if (i == path.length - 1) { if (i == path.length - 1) {
return currentObj; return currentObj;
@@ -74,8 +73,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
Object pathSegment = path[i]; Object pathSegment = path[i];
if (pathSegment == null) return null; if (pathSegment == null) return null;
CompoundTag t = (CompoundTag) currentTag; CompoundTag t = (CompoundTag) currentTag;
String key = pathSegment.toString(); currentTag = t.get(pathSegment.toString());
currentTag = t.get(key);
if (currentTag == null) return null; if (currentTag == null) return null;
if (i == path.length - 1) { if (i == path.length - 1) {
return currentTag; return currentTag;
@@ -424,30 +422,6 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
} }
} }
@Override
protected void addEnchantment(ComponentItemWrapper item, Enchantment enchantment) {
Object enchant = item.getComponentExact(ComponentTypes.ENCHANTMENTS);
try {
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
map.put(enchantment.id().toString(), enchantment.level());
item.setJavaComponent(ComponentTypes.ENCHANTMENTS, map);
} catch (ReflectiveOperationException e) {
plugin.logger().warn("Failed to add enchantment", e);
}
}
@Override
protected void addStoredEnchantment(ComponentItemWrapper item, Enchantment enchantment) {
Object enchant = item.getComponentExact(ComponentTypes.STORED_ENCHANTMENTS);
try {
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
map.put(enchantment.id().toString(), enchantment.level());
item.setJavaComponent(ComponentTypes.STORED_ENCHANTMENTS, map);
} catch (ReflectiveOperationException e) {
plugin.logger().warn("Failed to add stored enchantment", e);
}
}
@Override @Override
protected void itemFlags(ComponentItemWrapper item, List<String> flags) { protected void itemFlags(ComponentItemWrapper item, List<String> flags) {
throw new UnsupportedOperationException("This feature is not available on 1.20.5+"); throw new UnsupportedOperationException("This feature is not available on 1.20.5+");

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.bukkit.item.factory;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.saicone.rtag.data.ComponentType;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper; import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
import net.momirealms.craftengine.bukkit.item.ComponentTypes; import net.momirealms.craftengine.bukkit.item.ComponentTypes;
@@ -17,7 +16,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@SuppressWarnings("UnstableApiUsage")
public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 { public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
public ComponentItemFactory1_21_5(CraftEngine plugin) { public ComponentItemFactory1_21_5(CraftEngine plugin) {
@@ -116,9 +114,7 @@ public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
@Override @Override
protected Optional<JukeboxPlayable> jukeboxSong(ComponentItemWrapper item) { protected Optional<JukeboxPlayable> jukeboxSong(ComponentItemWrapper item) {
if (!item.hasComponent(ComponentTypes.JUKEBOX_PLAYABLE)) return Optional.empty(); if (!item.hasComponent(ComponentTypes.JUKEBOX_PLAYABLE)) return Optional.empty();
String song = (String) ComponentType.encodeJava( String song = (String) item.getJavaComponent(ComponentTypes.JUKEBOX_PLAYABLE).orElse(null);
ComponentTypes.JUKEBOX_PLAYABLE,
item.getComponentExact(ComponentTypes.JUKEBOX_PLAYABLE)).orElse(null);
if (song == null) return Optional.empty(); if (song == null) return Optional.empty();
return Optional.of(new JukeboxPlayable(song, true)); return Optional.of(new JukeboxPlayable(song, true));
} }

View File

@@ -1,10 +1,5 @@
package net.momirealms.craftengine.bukkit.item.factory; package net.momirealms.craftengine.bukkit.item.factory;
import com.saicone.rtag.RtagItem;
import com.saicone.rtag.item.ItemObject;
import com.saicone.rtag.tag.TagBase;
import com.saicone.rtag.tag.TagCompound;
import com.saicone.rtag.tag.TagList;
import net.momirealms.craftengine.bukkit.item.LegacyItemWrapper; import net.momirealms.craftengine.bukkit.item.LegacyItemWrapper;
import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries;
@@ -32,7 +27,7 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
@Override @Override
protected LegacyItemWrapper wrapInternal(ItemStack item) { protected LegacyItemWrapper wrapInternal(ItemStack item) {
return new LegacyItemWrapper(new RtagItem(item)); return new LegacyItemWrapper(item);
} }
@Override @Override
@@ -212,38 +207,6 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
item.setTag(tags, "StoredEnchantments"); item.setTag(tags, "StoredEnchantments");
} }
@Override
protected void addEnchantment(LegacyItemWrapper item, Enchantment enchantment) {
Object enchantments = item.getExactTag("Enchantments");
if (enchantments != null) {
for (Object enchant : TagList.getValue(enchantments)) {
if (TagBase.getValue(TagCompound.get(enchant, "id")).equals(enchant.toString())) {
TagCompound.set(enchant, "lvl", TagBase.newTag(enchantment.level()));
return;
}
}
item.add(Map.of("id", enchantment.id().toString(), "lvl", (short) enchantment.level()), "Enchantments");
} else {
item.setTag(List.of(Map.of("id", enchantment.id().toString(), "lvl", (short) enchantment.level())), "Enchantments");
}
}
@Override
protected void addStoredEnchantment(LegacyItemWrapper item, Enchantment enchantment) {
Object enchantments = item.getExactTag("StoredEnchantments");
if (enchantments != null) {
for (Object enchant : TagList.getValue(enchantments)) {
if (TagBase.getValue(TagCompound.get(enchant, "id")).equals(enchant.toString())) {
TagCompound.set(enchant, "lvl", TagBase.newTag(enchantment.level()));
return;
}
}
item.add(Map.of("id", enchantment.id().toString(), "lvl", (short) enchantment.level()), "StoredEnchantments");
} else {
item.setTag(List.of(Map.of("id", enchantment.id().toString(), "lvl", (short) enchantment.level())), "StoredEnchantments");
}
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
protected Optional<Enchantment> getEnchantment(LegacyItemWrapper item, Key key) { protected Optional<Enchantment> getEnchantment(LegacyItemWrapper item, Key key) {
@@ -307,33 +270,33 @@ public class UniversalItemFactory extends BukkitItemFactory<LegacyItemWrapper> {
@Override @Override
protected LegacyItemWrapper mergeCopy(LegacyItemWrapper item1, LegacyItemWrapper item2) { protected LegacyItemWrapper mergeCopy(LegacyItemWrapper item1, LegacyItemWrapper item2) {
Object itemStack = ItemObject.copy(item2.getLiteralObject()); Object copied = FastNMS.INSTANCE.constructor$ItemStack(FastNMS.INSTANCE.method$ItemStack$getItem(item2.getLiteralObject()), item2.count());
FastNMS.INSTANCE.method$ItemStack$setTag(itemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject()))); Object copiedTag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(copied);
// one more step than vanilla FastNMS.INSTANCE.method$CompoundTag$merge(copiedTag, FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject()));
TagCompound.merge(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(itemStack), FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject()), true, true); FastNMS.INSTANCE.method$CompoundTag$merge(copiedTag, FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject()));
return new LegacyItemWrapper(new RtagItem(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack))); return new LegacyItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(copied));
} }
@Override @Override
protected void merge(LegacyItemWrapper item1, LegacyItemWrapper item2) { protected void merge(LegacyItemWrapper item1, LegacyItemWrapper item2) {
// load previous changes on nms items Object item1Tag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject());
item1.load(); Object item2Tag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject());
TagCompound.merge(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item1.getLiteralObject()), FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item2.getLiteralObject()), true, true); FastNMS.INSTANCE.method$CompoundTag$merge(item1Tag, item2Tag);
// update wrapped item
item1.update();
} }
@Override @Override
protected LegacyItemWrapper transmuteCopy(LegacyItemWrapper item, Key newItem, int amount) { protected LegacyItemWrapper transmuteCopy(LegacyItemWrapper item, Key newItem, int amount) {
Object newItemStack = FastNMS.INSTANCE.constructor$ItemStack(FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(newItem)), amount); Object copied = FastNMS.INSTANCE.constructor$ItemStack(FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(newItem)), amount);
FastNMS.INSTANCE.method$ItemStack$setTag(newItemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject()))); Object copiedTag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(copied);
return new LegacyItemWrapper(new RtagItem(ItemObject.asCraftMirror(newItemStack))); Object thisTag = FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject());
FastNMS.INSTANCE.method$CompoundTag$merge(copiedTag, thisTag);
return new LegacyItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(copied));
} }
@Override @Override
protected LegacyItemWrapper unsafeTransmuteCopy(LegacyItemWrapper item, Object newItem, int amount) { protected LegacyItemWrapper unsafeTransmuteCopy(LegacyItemWrapper item, Object newItem, int amount) {
Object newItemStack = FastNMS.INSTANCE.constructor$ItemStack(newItem, amount); Object newItemStack = FastNMS.INSTANCE.constructor$ItemStack(newItem, amount);
FastNMS.INSTANCE.method$ItemStack$setTag(newItemStack, TagCompound.clone(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject()))); FastNMS.INSTANCE.method$ItemStack$setTag(newItemStack, FastNMS.INSTANCE.method$CompoundTag$copy(FastNMS.INSTANCE.field$ItemStack$getOrCreateTag(item.getLiteralObject())));
return new LegacyItemWrapper(new RtagItem(ItemObject.asCraftMirror(newItemStack))); return new LegacyItemWrapper(FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(newItemStack));
} }
} }

View File

@@ -96,7 +96,6 @@ public class DebugStickListener implements Listener {
currentProperty = getRelative(properties, currentProperty, player.isSecondaryUseActive()); currentProperty = getRelative(properties, currentProperty, player.isSecondaryUseActive());
data.put(blockId, currentProperty.name()); data.put(blockId, currentProperty.name());
wrapped.setTag(data, "craftengine:debug_stick_state"); wrapped.setTag(data, "craftengine:debug_stick_state");
wrapped.load();
Object systemChatPacket = NetworkReflections.constructor$ClientboundSystemChatPacket.newInstance( Object systemChatPacket = NetworkReflections.constructor$ClientboundSystemChatPacket.newInstance(
ComponentUtils.adventureToMinecraft(Component.translatable("item.minecraft.debug_stick.select") ComponentUtils.adventureToMinecraft(Component.translatable("item.minecraft.debug_stick.select")
.arguments( .arguments(

View File

@@ -130,7 +130,8 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
} else if (VersionHelper.isOrAbove1_20_2()) { } else if (VersionHelper.isOrAbove1_20_2()) {
nmsRecipe = CoreReflections.constructor$RecipeHolder.newInstance(KeyUtils.toResourceLocation(id), nmsRecipe); nmsRecipe = CoreReflections.constructor$RecipeHolder.newInstance(KeyUtils.toResourceLocation(id), nmsRecipe);
} else { } else {
return () -> {}; Object finalNmsRecipe0 = nmsRecipe;
return () -> registerNMSSmithingRecipe(finalNmsRecipe0);
} }
Object finalNmsRecipe = nmsRecipe; Object finalNmsRecipe = nmsRecipe;
return () -> registerNMSSmithingRecipe(finalNmsRecipe); return () -> registerNMSSmithingRecipe(finalNmsRecipe);

View File

@@ -643,7 +643,7 @@ public class RecipeEventListener implements Listener {
} }
afterPenalty = calculateIncreasedRepairCost(afterPenalty); afterPenalty = calculateIncreasedRepairCost(afterPenalty);
wrappedFirst.repairCost(afterPenalty); wrappedFirst.repairCost(afterPenalty);
event.setResult(wrappedFirst.load()); event.setResult(wrappedFirst.getItem());
} }
} }
@@ -757,7 +757,7 @@ public class RecipeEventListener implements Listener {
int remainingDurability = totalMaxDamage - totalDamage; int remainingDurability = totalMaxDamage - totalDamage;
int newItemDamage = Math.max(0, newItem.maxDamage() - remainingDurability); int newItemDamage = Math.max(0, newItem.maxDamage() - remainingDurability);
newItem.damage(newItemDamage); newItem.damage(newItemDamage);
inventory.setResult(newItem.load()); inventory.setResult(newItem.getItem());
} else if (CoreReflections.clazz$ArmorDyeRecipe.isInstance(mcRecipe)) { } else if (CoreReflections.clazz$ArmorDyeRecipe.isInstance(mcRecipe)) {
ItemStack[] itemStacks = inventory.getMatrix(); ItemStack[] itemStacks = inventory.getMatrix();
for (ItemStack itemStack : itemStacks) { for (ItemStack itemStack : itemStacks) {

View File

@@ -1,9 +1,8 @@
package net.momirealms.craftengine.bukkit.plugin.command.feature; package net.momirealms.craftengine.bukkit.plugin.command.feature;
import com.saicone.rtag.item.ItemTagStream; import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
import net.momirealms.craftengine.bukkit.util.ItemUtils; import net.momirealms.craftengine.bukkit.util.ItemUtils;
import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
@@ -28,11 +27,9 @@ public class DebugItemDataCommand extends BukkitCommandFeature<CommandSender> {
.handler(context -> { .handler(context -> {
ItemStack itemInHand = context.sender().getInventory().getItemInMainHand(); ItemStack itemInHand = context.sender().getInventory().getItemInMainHand();
if (ItemUtils.isEmpty(itemInHand)) { if (ItemUtils.isEmpty(itemInHand)) {
plugin().senderFactory().wrap(context.sender()).sendMessage(Component.text("Please hold an item").color(NamedTextColor.RED));
return; return;
} }
Map<String, Object> readableMap = toReadableMap(itemInHand); Map<String, Object> readableMap = toMap(itemInHand);
readableMap.remove("rtagDataVersion");
List<String> readableList = mapToList(readableMap); List<String> readableList = mapToList(readableMap);
StringJoiner joiner = new StringJoiner("<newline><reset>"); StringJoiner joiner = new StringJoiner("<newline><reset>");
for (String text : readableList) { for (String text : readableList) {
@@ -47,13 +44,10 @@ public class DebugItemDataCommand extends BukkitCommandFeature<CommandSender> {
return "debug_item_data"; return "debug_item_data";
} }
@SuppressWarnings("unchecked")
public static Map<String, Object> toReadableMap(ItemStack item) {
return toMap(item);
}
private static Map<String, Object> toMap(ItemStack object) { private static Map<String, Object> toMap(ItemStack object) {
return ItemTagStream.INSTANCE.toMap(object); Object tag = FastNMS.INSTANCE.method$itemStack$save(FastNMS.INSTANCE.field$CraftItemStack$handle(object), FastNMS.INSTANCE.constructor$CompoundTag());
return (Map<String, Object>) MRegistryOps.NBT.convertTo(MRegistryOps.JAVA, tag);
} }
private List<String> mapToList(Map<String, Object> readableDataMap) { private List<String> mapToList(Map<String, Object> readableDataMap) {

View File

@@ -79,7 +79,7 @@ public class TotemAnimationCommand extends BukkitCommandFeature<CommandSender> {
item.setComponent(ComponentTypes.DEATH_PROTECTION, Map.of()); item.setComponent(ComponentTypes.DEATH_PROTECTION, Map.of());
} }
} }
ItemStack totemItem = item.load(); ItemStack totemItem = item.getItem();
MultiplePlayerSelector selector = context.get("players"); MultiplePlayerSelector selector = context.get("players");
for (Player player : selector.values()) { for (Player player : selector.values()) {
PlayerUtils.sendTotemAnimation(player, totemItem); PlayerUtils.sendTotemAnimation(player, totemItem);

View File

@@ -3560,4 +3560,11 @@ public final class CoreReflections {
"world.level.block.state.properties.BlockStateProperties" "world.level.block.state.properties.BlockStateProperties"
) )
); );
public static final Class<?> clazz$CompoundTag = requireNonNull(
BukkitReflectionUtils.findReobfOrMojmapClass(
"nbt.NBTTagCompound",
"nbt.CompoundTag"
)
);
} }

View File

@@ -71,7 +71,7 @@ public class BukkitWorld implements World {
@Override @Override
public void dropItemNaturally(Position location, Item<?> item) { public void dropItemNaturally(Position location, Item<?> item) {
ItemStack itemStack = (ItemStack) item.load(); ItemStack itemStack = (ItemStack) item.getItem();
if (ItemUtils.isEmpty(itemStack)) return; if (ItemUtils.isEmpty(itemStack)) return;
if (VersionHelper.isOrAbove1_21_2()) { if (VersionHelper.isOrAbove1_21_2()) {
platformWorld().dropItemNaturally(new Location(null, location.x(), location.y(), location.z()), (ItemStack) item.getItem()); platformWorld().dropItemNaturally(new Location(null, location.x(), location.y(), location.z()), (ItemStack) item.getItem());

View File

@@ -87,7 +87,6 @@ tasks {
archiveFileName = "craft-engine-core-${rootProject.properties["project_version"]}.jar" archiveFileName = "craft-engine-core-${rootProject.properties["project_version"]}.jar"
relocate("net.kyori", "net.momirealms.craftengine.libraries") relocate("net.kyori", "net.momirealms.craftengine.libraries")
relocate("dev.dejvokep", "net.momirealms.craftengine.libraries") relocate("dev.dejvokep", "net.momirealms.craftengine.libraries")
relocate("com.saicone.rtag", "net.momirealms.craftengine.libraries.rtag")
relocate("org.yaml.snakeyaml", "net.momirealms.craftengine.libraries.snakeyaml") relocate("org.yaml.snakeyaml", "net.momirealms.craftengine.libraries.snakeyaml")
relocate("net.kyori", "net.momirealms.craftengine.libraries") relocate("net.kyori", "net.momirealms.craftengine.libraries")
relocate("org.ahocorasick", "net.momirealms.craftengine.libraries.ahocorasick") relocate("org.ahocorasick", "net.momirealms.craftengine.libraries.ahocorasick")

View File

@@ -11,7 +11,6 @@ import net.momirealms.craftengine.core.plugin.context.event.EventFunctions;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.QuaternionUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils; import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.incendo.cloud.suggestion.Suggestion; import org.incendo.cloud.suggestion.Suggestion;
import org.joml.Vector3f; import org.joml.Vector3f;

View File

@@ -276,24 +276,12 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
return this; return this;
} }
@Override
public Item<I> addEnchantment(Enchantment enchantment) {
this.factory.addEnchantment(this.item, enchantment);
return this;
}
@Override @Override
public Item<I> setStoredEnchantments(List<Enchantment> enchantments) { public Item<I> setStoredEnchantments(List<Enchantment> enchantments) {
this.factory.storedEnchantments(this.item, enchantments); this.factory.storedEnchantments(this.item, enchantments);
return this; return this;
} }
@Override
public Item<I> addStoredEnchantment(Enchantment enchantment) {
this.factory.addStoredEnchantment(this.item, enchantment);
return this;
}
@Override @Override
public int maxStackSize() { public int maxStackSize() {
return this.factory.maxStackSize(this.item); return this.factory.maxStackSize(this.item);
@@ -397,11 +385,6 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
return this.factory.getItem(this.item); return this.factory.getItem(this.item);
} }
@Override
public I load() {
return this.factory.load(this.item);
}
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
@Override @Override
public AbstractItem<W, I> copyWithCount(int count) { public AbstractItem<W, I> copyWithCount(int count) {

View File

@@ -122,12 +122,8 @@ public interface Item<I> {
Item<I> setEnchantments(List<Enchantment> enchantments); Item<I> setEnchantments(List<Enchantment> enchantments);
Item<I> addEnchantment(Enchantment enchantment);
Item<I> setStoredEnchantments(List<Enchantment> enchantments); Item<I> setStoredEnchantments(List<Enchantment> enchantments);
Item<I> addStoredEnchantment(Enchantment enchantment);
Item<I> itemFlags(List<String> flags); Item<I> itemFlags(List<String> flags);
Object getJavaTag(Object... path); Object getJavaTag(Object... path);
@@ -164,8 +160,6 @@ public interface Item<I> {
I getItem(); I getItem();
I load();
int maxStackSize(); int maxStackSize();
Item<I> maxStackSize(int amount); Item<I> maxStackSize(int amount);

View File

@@ -57,8 +57,6 @@ public abstract class ItemFactory<W extends ItemWrapper<I>, I> {
protected abstract void resetComponent(W item, Object type); protected abstract void resetComponent(W item, Object type);
protected abstract I load(W item);
protected abstract I getItem(W item); protected abstract I getItem(W item);
protected abstract void customModelData(W item, Integer data); protected abstract void customModelData(W item, Integer data);
@@ -139,10 +137,6 @@ public abstract class ItemFactory<W extends ItemWrapper<I>, I> {
protected abstract void storedEnchantments(W item, List<Enchantment> enchantments); protected abstract void storedEnchantments(W item, List<Enchantment> enchantments);
protected abstract void addEnchantment(W item, Enchantment enchantment);
protected abstract void addStoredEnchantment(W item, Enchantment enchantment);
protected abstract Optional<Enchantment> getEnchantment(W item, Key key); protected abstract Optional<Enchantment> getEnchantment(W item, Key key);
protected abstract void itemFlags(W item, List<String> flags); protected abstract void itemFlags(W item, List<String> flags);

View File

@@ -4,8 +4,6 @@ public interface ItemWrapper<I> {
I getItem(); I getItem();
I load();
Object getLiteralObject(); Object getLiteralObject();
int count(); int count();

View File

@@ -102,7 +102,7 @@ public class CustomSmithingTransformRecipe<T> implements Recipe<T> {
for (ItemDataProcessor processor : this.processors) { for (ItemDataProcessor processor : this.processors) {
processor.accept(base, wrappedResult, finalResult); processor.accept(base, wrappedResult, finalResult);
} }
return finalResult.load(); return finalResult.getItem();
} }
@Override @Override

View File

@@ -9,8 +9,6 @@ import net.momirealms.sparrow.nbt.CompoundTag;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;

View File

@@ -6,7 +6,6 @@ import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs; import com.google.common.jimfs.Jimfs;
import com.google.gson.*; import com.google.gson.*;
import dev.dejvokep.boostedyaml.YamlDocument; import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.momirealms.craftengine.core.font.BitmapImage; import net.momirealms.craftengine.core.font.BitmapImage;
import net.momirealms.craftengine.core.font.Font; import net.momirealms.craftengine.core.font.Font;
@@ -564,7 +563,7 @@ public abstract class AbstractPackManager implements PackManager {
} else { } else {
if (configEntry.getValue() instanceof Map<?, ?> configSection0) { if (configEntry.getValue() instanceof Map<?, ?> configSection0) {
Map<String, Object> config = castToMap(configSection0, false); Map<String, Object> config = castToMap(configSection0, false);
if (Config.debug() && (boolean) config.getOrDefault("debug", false)) { if ((boolean) config.getOrDefault("debug", false)) {
this.plugin.logger().info(GsonHelper.get().toJson(this.plugin.templateManager().applyTemplates(id, config))); this.plugin.logger().info(GsonHelper.get().toJson(this.plugin.templateManager().applyTemplates(id, config)));
} }
if ((boolean) config.getOrDefault("enable", true)) { if ((boolean) config.getOrDefault("enable", true)) {

View File

@@ -167,7 +167,6 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
} }
item.customNameJson(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(it.displayName(), ItemBuildContext.EMPTY.tagResolvers()))); item.customNameJson(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(it.displayName(), ItemBuildContext.EMPTY.tagResolvers())));
item.loreJson(it.displayLore().stream().map(lore -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(lore, ItemBuildContext.EMPTY.tagResolvers()))).toList()); item.loreJson(it.displayLore().stream().map(lore -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(lore, ItemBuildContext.EMPTY.tagResolvers()))).toList());
item.load();
return new ItemWithAction(item, (element, click) -> { return new ItemWithAction(item, (element, click) -> {
click.cancel(); click.cancel();
player.playSound(Constants.SOUND_CLICK_BUTTON); player.playSound(Constants.SOUND_CLICK_BUTTON);
@@ -252,12 +251,10 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
item = this.plugin.itemManager().createWrappedItem(ItemKeys.BARRIER, player); item = this.plugin.itemManager().createWrappedItem(ItemKeys.BARRIER, player);
item.customNameJson(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(subCategory.displayName(), ItemBuildContext.EMPTY.tagResolvers()))); item.customNameJson(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(subCategory.displayName(), ItemBuildContext.EMPTY.tagResolvers())));
item.loreJson(subCategory.displayLore().stream().map(lore -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(lore, ItemBuildContext.EMPTY.tagResolvers()))).toList()); item.loreJson(subCategory.displayLore().stream().map(lore -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(lore, ItemBuildContext.EMPTY.tagResolvers()))).toList());
item.load();
} }
} else { } else {
item.customNameJson(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(subCategory.displayName(), ItemBuildContext.EMPTY.tagResolvers()))); item.customNameJson(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(subCategory.displayName(), ItemBuildContext.EMPTY.tagResolvers())));
item.loreJson(subCategory.displayLore().stream().map(lore -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(lore, ItemBuildContext.EMPTY.tagResolvers()))).toList()); item.loreJson(subCategory.displayLore().stream().map(lore -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(lore, ItemBuildContext.EMPTY.tagResolvers()))).toList());
item.load();
} }
return new ItemWithAction(item, (element, click) -> { return new ItemWithAction(item, (element, click) -> {
click.cancel(); click.cancel();
@@ -272,7 +269,6 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
if (!itemId.equals(ItemKeys.AIR)) { if (!itemId.equals(ItemKeys.AIR)) {
item = this.plugin.itemManager().createWrappedItem(ItemKeys.BARRIER, player); item = this.plugin.itemManager().createWrappedItem(ItemKeys.BARRIER, player);
item.customNameJson(AdventureHelper.componentToJson(Component.text(it).decoration(TextDecoration.ITALIC, TextDecoration.State.FALSE).color(NamedTextColor.RED))); item.customNameJson(AdventureHelper.componentToJson(Component.text(it).decoration(TextDecoration.ITALIC, TextDecoration.State.FALSE).color(NamedTextColor.RED)));
item.load();
} }
canGoFurther = false; canGoFurther = false;
} else { } else {

View File

@@ -93,9 +93,9 @@ public class MiscUtils {
if (split.length == 4) { if (split.length == 4) {
return new Quaternionf(Float.parseFloat(split[0]), Float.parseFloat(split[1]), Float.parseFloat(split[2]), Float.parseFloat(split[3])); return new Quaternionf(Float.parseFloat(split[0]), Float.parseFloat(split[1]), Float.parseFloat(split[2]), Float.parseFloat(split[3]));
} else if (split.length == 3) { } else if (split.length == 3) {
return QuaternionUtils.toQuaternionf(Math.toRadians(-Float.parseFloat(split[2])), Math.toRadians(-Float.parseFloat(split[1])), Math.toRadians(-Float.parseFloat(split[0]))); return QuaternionUtils.toQuaternionf((float) Math.toRadians(Float.parseFloat(split[2])), (float) Math.toRadians(Float.parseFloat(split[1])), (float) Math.toRadians(Float.parseFloat(split[0])));
} else if (split.length == 1) { } else if (split.length == 1) {
return QuaternionUtils.toQuaternionf(0, Math.toRadians(-Float.parseFloat(split[0])), 0); return QuaternionUtils.toQuaternionf(0, (float) -Math.toRadians(Float.parseFloat(split[0])), 0);
} else { } else {
throw new LocalizedResourceConfigException("warning.config.type.quaternionf", stringFormat, option); throw new LocalizedResourceConfigException("warning.config.type.quaternionf", stringFormat, option);
} }

View File

@@ -1,7 +1,6 @@
package net.momirealms.craftengine.core.util; package net.momirealms.craftengine.core.util;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f;
public class QuaternionUtils { public class QuaternionUtils {
@@ -21,23 +20,17 @@ public class QuaternionUtils {
return new Quaternionf(x, y, z, w); return new Quaternionf(x, y, z, w);
} }
public static Vector3f toEulerAngle(Quaternionf quaternionf) { public static Quaternionf toQuaternionf(float yaw, float pitch, float roll) {
float x = quaternionf.x; float cy = MCUtils.cos(yaw * 0.5f);
float y = quaternionf.y; float sy = MCUtils.sin(yaw * 0.5f);
float z = quaternionf.z; float cp = MCUtils.cos(pitch * 0.5f);
float w = quaternionf.w; float sp = MCUtils.sin(pitch * 0.5f);
float siny_cosp = 2 * (w * z + x * y); float cr = MCUtils.cos(roll * 0.5f);
float cosy_cosp = 1 - 2 * (y * y + z * z); float sr = MCUtils.sin(roll * 0.5f);
float yaw = (float) Math.atan2(siny_cosp, cosy_cosp); float w = cr * cp * cy + sr * sp * sy;
float sinp = 2 * (w * y - z * x); float x = sr * cp * cy - cr * sp * sy;
float pitch = (float) Math.asin(sinp); float y = cr * sp * cy + sr * cp * sy;
float sinr_cosp = 2 * (w * x + y * z); float z = cr * cp * sy - sr * sp * cy;
float cosr_cosp = 1 - 2 * (x * x + y * y); return new Quaternionf(x, y, z, w);
float roll = (float) Math.atan2(sinr_cosp, cosr_cosp);
return new Vector3f(yaw, pitch, roll);
}
public static double quaternionToPitch(Quaternionf quaternionf) {
return 2 * Math.atan2(quaternionf.y, quaternionf.w);
} }
} }

View File

@@ -30,7 +30,6 @@ cloud_minecraft_extras_version=2.0.0-beta.10
boosted_yaml_version=1.3.7 boosted_yaml_version=1.3.7
bstats_version=3.1.0 bstats_version=3.1.0
caffeine_version=3.2.0 caffeine_version=3.2.0
rtag_version=1.5.10
placeholder_api_version=2.11.6 placeholder_api_version=2.11.6
vault_version=1.7 vault_version=1.7
guava_version=33.4.6-jre guava_version=33.4.6-jre
@@ -51,7 +50,7 @@ byte_buddy_version=1.17.5
ahocorasick_version=0.6.3 ahocorasick_version=0.6.3
snake_yaml_version=2.4 snake_yaml_version=2.4
anti_grief_version=0.17 anti_grief_version=0.17
nms_helper_version=1.0.14 nms_helper_version=1.0.18
evalex_version=3.5.0 evalex_version=3.5.0
reactive_streams_version=1.0.4 reactive_streams_version=1.0.4
amazon_awssdk_version=2.31.23 amazon_awssdk_version=2.31.23