mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 04:19:27 +00:00
盔甲重构part2
This commit is contained in:
@@ -15,7 +15,10 @@ import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.ThrowableProjectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@@ -29,7 +32,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class BukkitProjectileManager implements Listener, ProjectileManager {
|
||||
private static BukkitProjectileManager instance;
|
||||
|
||||
@@ -11,12 +11,10 @@ import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistries;
|
||||
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.ItemUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.*;
|
||||
import net.momirealms.craftengine.core.item.equipment.TrimBasedEquipment;
|
||||
import net.momirealms.craftengine.core.item.modifier.IdModifier;
|
||||
import net.momirealms.craftengine.core.pack.AbstractPackManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
@@ -52,7 +50,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
private final ArmorEventListener armorEventListener;
|
||||
private final NetworkItemHandler<ItemStack> networkItemHandler;
|
||||
private final Object bedrockItemHolder;
|
||||
private boolean registeredTrimMaterial;
|
||||
private Set<Key> lastRegisteredPatterns = Set.of();
|
||||
|
||||
public BukkitItemManager(BukkitCraftEngine plugin) {
|
||||
super(plugin);
|
||||
@@ -65,6 +63,8 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
this.networkItemHandler = VersionHelper.isOrAbove1_20_5() ? new ModernNetworkItemHandler() : new LegacyNetworkItemHandler();
|
||||
this.registerAllVanillaItems();
|
||||
this.bedrockItemHolder = FastNMS.INSTANCE.method$Registry$getHolderByResourceKey(MBuiltInRegistries.ITEM, FastNMS.INSTANCE.method$ResourceKey$create(MRegistries.ITEM, KeyUtils.toResourceLocation(Key.of("minecraft:bedrock")))).get();;
|
||||
this.registerCustomTrimMaterial();
|
||||
this.loadLastRegisteredPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,20 +136,22 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
HandlerList.unregisterAll(this.itemEventListener);
|
||||
HandlerList.unregisterAll(this.debugStickListener);
|
||||
HandlerList.unregisterAll(this.armorEventListener);
|
||||
this.persistLastRegisteredPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerArmorTrimPattern(Collection<TrimBasedEquipment> equipments) {
|
||||
protected void registerArmorTrimPattern(Collection<Key> equipments) {
|
||||
if (equipments.isEmpty()) return;
|
||||
this.registerCustomTrimMaterial();
|
||||
this.lastRegisteredPatterns = new HashSet<>(equipments);
|
||||
this.lastRegisteredPatterns.add(Config.sacrificedAssetId());
|
||||
Object registry = FastNMS.INSTANCE.method$RegistryAccess$lookupOrThrow(FastNMS.INSTANCE.registryAccess(), MRegistries.TRIM_PATTERN);
|
||||
try {
|
||||
CoreReflections.field$MappedRegistry$frozen.set(registry, false);
|
||||
for (TrimBasedEquipment equipment : equipments) {
|
||||
Object resourceLocation = KeyUtils.toResourceLocation(equipment.assetId());
|
||||
for (Key assetId : this.lastRegisteredPatterns) {
|
||||
Object resourceLocation = KeyUtils.toResourceLocation(assetId);
|
||||
Object previous = FastNMS.INSTANCE.method$Registry$getValue(registry, resourceLocation);
|
||||
if (previous == null) {
|
||||
Object trimPattern = createTrimPattern(equipment.assetId());
|
||||
Object trimPattern = createTrimPattern(assetId);
|
||||
Object holder = CoreReflections.method$Registry$registerForHolder.invoke(null, registry, resourceLocation, trimPattern);
|
||||
CoreReflections.method$Holder$Reference$bindValue.invoke(holder, trimPattern);
|
||||
CoreReflections.field$Holder$Reference$tags.set(holder, Set.of());
|
||||
@@ -165,10 +167,15 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
}
|
||||
}
|
||||
|
||||
private void persistLastRegisteredPatterns() {
|
||||
}
|
||||
|
||||
private void loadLastRegisteredPatterns() {
|
||||
}
|
||||
|
||||
private void registerCustomTrimMaterial() {
|
||||
if (this.registeredTrimMaterial) return;
|
||||
Object registry = FastNMS.INSTANCE.method$RegistryAccess$lookupOrThrow(FastNMS.INSTANCE.registryAccess(), MRegistries.TRIM_MATERIAL);
|
||||
Object resourceLocation = KeyUtils.toResourceLocation(Key.of("minecraft", AbstractPackManager.TRIM_MATERIAL));
|
||||
Object resourceLocation = KeyUtils.toResourceLocation(Key.of("minecraft", AbstractPackManager.NEW_TRIM_MATERIAL));
|
||||
Object previous = FastNMS.INSTANCE.method$Registry$getValue(registry, resourceLocation);
|
||||
if (previous == null) {
|
||||
try {
|
||||
@@ -186,7 +193,6 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.registeredTrimMaterial = true;
|
||||
}
|
||||
|
||||
private Object createTrimPattern(Key key) throws ReflectiveOperationException {
|
||||
@@ -206,7 +212,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
} else if (VersionHelper.isOrAbove1_21_4()) {
|
||||
return CoreReflections.constructor$TrimMaterial.newInstance("custom", this.bedrockItemHolder, Map.of(), CoreReflections.instance$Component$empty);
|
||||
} else {
|
||||
return CoreReflections.constructor$TrimMaterial.newInstance("custom", this.bedrockItemHolder, 1_000_000.0f, Map.of(), CoreReflections.instance$Component$empty);
|
||||
return CoreReflections.constructor$TrimMaterial.newInstance("custom", this.bedrockItemHolder, 0f, Map.of(), CoreReflections.instance$Component$empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,16 +3,13 @@ package net.momirealms.craftengine.bukkit.item.factory;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
|
||||
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
|
||||
import net.momirealms.craftengine.core.entity.EquipmentSlot;
|
||||
import net.momirealms.craftengine.core.item.equipment.Equipments;
|
||||
import net.momirealms.craftengine.core.item.setting.EquipmentData;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.sparrow.nbt.CompoundTag;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ComponentItemFactory1_21_2 extends ComponentItemFactory1_21 {
|
||||
|
||||
@@ -12,7 +12,6 @@ import net.momirealms.craftengine.core.sound.JukeboxSong;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
Reference in New Issue
Block a user