From 283d5e86c1ce16d15444a00c70710b3f74e8da0e Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sat, 6 Dec 2025 23:02:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AE=B6=E5=85=B7=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E5=85=83=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../element/ArmorStandBlockEntityElement.java | 31 +++++++++++++- .../ArmorStandBlockEntityElementConfig.java | 42 ++++++++++++++----- .../element/ItemBlockEntityElementConfig.java | 6 +-- .../ItemDisplayBlockEntityElementConfig.java | 32 +++++++------- .../TextDisplayBlockEntityElementConfig.java | 18 ++++---- .../element/ArmorStandFurnitureElement.java | 34 +++++++++++++-- .../ArmorStandFurnitureElementConfig.java | 26 ++++++++++-- .../hitbox/CustomFurnitureHitbox.java | 12 ++---- .../hitbox/HappyGhastFurnitureHitbox.java | 12 ++---- .../hitbox/ShulkerFurnitureHitbox.java | 10 ++--- .../reflection/minecraft/CoreReflections.java | 11 +++-- .../plugin/user/BukkitServerPlayer.java | 3 +- .../core/block/AbstractBlockManager.java | 6 +++ .../furniture/AbstractFurnitureManager.java | 8 ++++ .../craftengine/core/world/Glowing.java | 10 +++++ gradle.properties | 2 +- 16 files changed, 182 insertions(+), 81 deletions(-) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/world/Glowing.java diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElement.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElement.java index dee58c501..1d6909905 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElement.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElement.java @@ -4,21 +4,29 @@ import com.mojang.datafixers.util.Pair; import it.unimi.dsi.fastutil.ints.IntList; import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections; +import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MAttributeHolders; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes; +import net.momirealms.craftengine.bukkit.world.score.BukkitTeamManager; import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement; import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.util.VersionHelper; import net.momirealms.craftengine.core.world.BlockPos; import org.joml.Vector3f; +import java.util.Collections; import java.util.List; import java.util.UUID; +import java.util.function.Consumer; public class ArmorStandBlockEntityElement implements BlockEntityElement { public final ArmorStandBlockEntityElementConfig config; public final Object cachedSpawnPacket; public final Object cachedDespawnPacket; public final Object cachedUpdatePosPacket; + public final Object cachedScalePacket; + public final Object cachedTeamPacket; public final int entityId; + public final UUID uuid = UUID.randomUUID(); public ArmorStandBlockEntityElement(ArmorStandBlockEntityElementConfig config, BlockPos pos) { this(config, pos, CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet(), false); @@ -27,13 +35,28 @@ public class ArmorStandBlockEntityElement implements BlockEntityElement { public ArmorStandBlockEntityElement(ArmorStandBlockEntityElementConfig config, BlockPos pos, int entityId, boolean posChanged) { Vector3f position = config.position(); this.cachedSpawnPacket = FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( - entityId, UUID.randomUUID(), pos.x() + position.x, pos.y() + position.y, pos.z() + position.z, + entityId, this.uuid, pos.x() + position.x, pos.y() + position.y, pos.z() + position.z, config.xRot(), config.yRot(), MEntityTypes.ARMOR_STAND, 0, CoreReflections.instance$Vec3$Zero, config.yRot() ); this.config = config; this.cachedDespawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(IntList.of(entityId)); this.entityId = entityId; this.cachedUpdatePosPacket = posChanged ? FastNMS.INSTANCE.constructor$ClientboundEntityPositionSyncPacket(this.entityId, pos.x() + position.x, pos.y() + position.y, pos.z() + position.z, config.yRot(), config.xRot(), false) : null; + if (VersionHelper.isOrAbove1_20_5() && config.scale() != 1) { + Object attributeIns = FastNMS.INSTANCE.constructor$AttributeInstance(MAttributeHolders.SCALE, (Consumer) (o) -> {}); + FastNMS.INSTANCE.method$AttributeInstance$setBaseValue(attributeIns, config.scale()); + this.cachedScalePacket = FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(entityId, Collections.singletonList(attributeIns)); + } else { + this.cachedScalePacket = null; + } + Object teamPacket = null; + if (config.glowColor != null) { + Object teamByColor = BukkitTeamManager.instance().getTeamByColor(config.glowColor); + if (teamByColor != null) { + teamPacket = FastNMS.INSTANCE.method$ClientboundSetPlayerTeamPacket$createMultiplePlayerPacket(teamByColor, List.of(this.uuid.toString()), true); + } + } + this.cachedTeamPacket = teamPacket; } @Override @@ -47,6 +70,12 @@ public class ArmorStandBlockEntityElement implements BlockEntityElement { player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundSetEquipmentPacket(this.entityId, List.of( Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, this.config.item(player).getLiteralObject()) )), false); + if (this.cachedDespawnPacket != null) { + player.sendPacket(this.cachedDespawnPacket, false); + } + if (this.cachedTeamPacket != null) { + player.sendPacket(this.cachedTeamPacket, false); + } } @Override diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElementConfig.java index f20b8100c..f0e99b90b 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElementConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElementConfig.java @@ -10,10 +10,13 @@ import net.momirealms.craftengine.core.entity.player.Player; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.item.ItemKeys; import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.LegacyChatFormatter; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import net.momirealms.craftengine.core.world.BlockPos; +import net.momirealms.craftengine.core.world.Glowing; import net.momirealms.craftengine.core.world.World; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; import org.joml.Vector3f; import java.util.ArrayList; @@ -21,23 +24,26 @@ import java.util.List; import java.util.Map; import java.util.function.Function; -public class ArmorStandBlockEntityElementConfig implements BlockEntityElementConfig { +public class ArmorStandBlockEntityElementConfig implements BlockEntityElementConfig, Glowing { public static final Factory FACTORY = new Factory(); - private final Function> lazyMetadataPacket; - private final Key itemId; - private final float scale; - private final Vector3f position; - private final float xRot; - private final float yRot; - private final boolean small; + public final Function> lazyMetadataPacket; + public final Key itemId; + public final float scale; + public final Vector3f position; + public final float xRot; + public final float yRot; + public final boolean small; + public final LegacyChatFormatter glowColor; public ArmorStandBlockEntityElementConfig(Key itemId, float scale, Vector3f position, float xRot, float yRot, - boolean small) { + boolean small, + LegacyChatFormatter glowColor) { this.itemId = itemId; + this.glowColor = glowColor; this.scale = scale; this.position = position; this.xRot = xRot; @@ -45,7 +51,11 @@ public class ArmorStandBlockEntityElementConfig implements BlockEntityElementCon this.small = small; this.lazyMetadataPacket = player -> { List dataValues = new ArrayList<>(2); - BaseEntityData.SharedFlags.addEntityData((byte) 0x20, dataValues); + if (glowColor != null) { + BaseEntityData.SharedFlags.addEntityData((byte) 0x60, dataValues); + } else { + BaseEntityData.SharedFlags.addEntityData((byte) 0x20, dataValues); + } if (small) { ArmorStandData.ArmorStandFlags.addEntityData((byte) 0x01, dataValues); } @@ -53,6 +63,12 @@ public class ArmorStandBlockEntityElementConfig implements BlockEntityElementCon }; } + @Nullable + @Override + public LegacyChatFormatter glowColor() { + return this.glowColor; + } + @Override public ArmorStandBlockEntityElement create(World world, BlockPos pos) { return new ArmorStandBlockEntityElement(this, pos); @@ -60,6 +76,9 @@ public class ArmorStandBlockEntityElementConfig implements BlockEntityElementCon @Override public ArmorStandBlockEntityElement create(World world, BlockPos pos, ArmorStandBlockEntityElement previous) { + if (previous.config.scale != scale || previous.config.glowColor != glowColor) { + return null; + } return new ArmorStandBlockEntityElement(this, pos, previous.entityId, previous.config.yRot != this.yRot || previous.config.xRot != this.xRot || @@ -129,7 +148,8 @@ public class ArmorStandBlockEntityElementConfig implements BlockEntityElementCon ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0.5f), "position"), ResourceConfigUtils.getAsFloat(arguments.getOrDefault("pitch", 0f), "pitch"), ResourceConfigUtils.getAsFloat(arguments.getOrDefault("yaw", 0f), "yaw"), - ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("small", false), "small") + ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("small", false), "small"), + ResourceConfigUtils.getAsEnum(arguments.get("glow-color"), LegacyChatFormatter.class, null) ); } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemBlockEntityElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemBlockEntityElementConfig.java index f49fd65f5..dadbd2d96 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemBlockEntityElementConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemBlockEntityElementConfig.java @@ -22,9 +22,9 @@ import java.util.function.Function; public class ItemBlockEntityElementConfig implements BlockEntityElementConfig { public static final Factory FACTORY = new Factory(); - private final Function> lazyMetadataPacket; - private final Key itemId; - private final Vector3f position; + public final Function> lazyMetadataPacket; + public final Key itemId; + public final Vector3f position; public ItemBlockEntityElementConfig(Key itemId, Vector3f position) { this.itemId = itemId; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemDisplayBlockEntityElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemDisplayBlockEntityElementConfig.java index ec00776e8..3dbd0ca1a 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemDisplayBlockEntityElementConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemDisplayBlockEntityElementConfig.java @@ -28,22 +28,22 @@ import java.util.function.Function; public class ItemDisplayBlockEntityElementConfig implements BlockEntityElementConfig { public static final Factory FACTORY = new Factory(); - private final Function> lazyMetadataPacket; - private final Key itemId; - private final Vector3f scale; - private final Vector3f position; - private final Vector3f translation; - private final float xRot; - private final float yRot; - private final Quaternionf rotation; - private final ItemDisplayContext displayContext; - private final Billboard billboard; - private final float shadowRadius; - private final float shadowStrength; - private final Color glowColor; - private final int blockLight; - private final int skyLight; - private final float viewRange; + public final Function> lazyMetadataPacket; + public final Key itemId; + public final Vector3f scale; + public final Vector3f position; + public final Vector3f translation; + public final float xRot; + public final float yRot; + public final Quaternionf rotation; + public final ItemDisplayContext displayContext; + public final Billboard billboard; + public final float shadowRadius; + public final float shadowStrength; + public final Color glowColor; + public final int blockLight; + public final int skyLight; + public final float viewRange; public ItemDisplayBlockEntityElementConfig(Key itemId, Vector3f scale, diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/TextDisplayBlockEntityElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/TextDisplayBlockEntityElementConfig.java index 3c27ed7d8..fcdc44fea 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/TextDisplayBlockEntityElementConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/TextDisplayBlockEntityElementConfig.java @@ -24,15 +24,15 @@ import java.util.function.Function; public class TextDisplayBlockEntityElementConfig implements BlockEntityElementConfig { public static final Factory FACTORY = new Factory(); - private final Function> lazyMetadataPacket; - private final String text; - private final Vector3f scale; - private final Vector3f position; - private final Vector3f translation; - private final float xRot; - private final float yRot; - private final Quaternionf rotation; - private final Billboard billboard; + public final Function> lazyMetadataPacket; + public final String text; + public final Vector3f scale; + public final Vector3f position; + public final Vector3f translation; + public final float xRot; + public final float yRot; + public final Quaternionf rotation; + public final Billboard billboard; public final Color glowColor; public final int blockLight; public final int skyLight; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ArmorStandFurnitureElement.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ArmorStandFurnitureElement.java index ba6495647..e25917dd5 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ArmorStandFurnitureElement.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ArmorStandFurnitureElement.java @@ -4,24 +4,31 @@ import com.mojang.datafixers.util.Pair; import it.unimi.dsi.fastutil.ints.IntList; import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections; +import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MAttributeHolders; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes; +import net.momirealms.craftengine.bukkit.world.score.BukkitTeamManager; import net.momirealms.craftengine.core.entity.furniture.Furniture; import net.momirealms.craftengine.core.entity.furniture.FurnitureColorSource; import net.momirealms.craftengine.core.entity.furniture.element.FurnitureElement; import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.util.VersionHelper; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.WorldPosition; +import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.function.Consumer; public class ArmorStandFurnitureElement implements FurnitureElement { private final ArmorStandFurnitureElementConfig config; - public final int entityId; private final FurnitureColorSource colorSource; public final Object cachedSpawnPacket; public final Object cachedDespawnPacket; + public final Object cachedScalePacket; + public final Object cachedTeamPacket; + public final int entityId; + public final UUID uuid = UUID.randomUUID(); public ArmorStandFurnitureElement(Furniture furniture, ArmorStandFurnitureElementConfig config) { this.config = config; @@ -29,11 +36,26 @@ public class ArmorStandFurnitureElement implements FurnitureElement { WorldPosition furniturePos = furniture.position(); Vec3d position = Furniture.getRelativePosition(furniturePos, config.position()); this.cachedSpawnPacket = FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( - entityId, UUID.randomUUID(), position.x, position.y, position.z, + this.entityId, this.uuid, position.x, position.y, position.z, furniturePos.xRot, furniturePos.yRot, MEntityTypes.ARMOR_STAND, 0, CoreReflections.instance$Vec3$Zero, furniturePos.yRot ); this.colorSource = furniture.dataAccessor.getColorSource(); - this.cachedDespawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(IntList.of(entityId)); + this.cachedDespawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(IntList.of(this.entityId)); + if (VersionHelper.isOrAbove1_20_5() && config.scale != 1) { + Object attributeIns = FastNMS.INSTANCE.constructor$AttributeInstance(MAttributeHolders.SCALE, (Consumer) (o) -> {}); + FastNMS.INSTANCE.method$AttributeInstance$setBaseValue(attributeIns, config.scale()); + this.cachedScalePacket = FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(this.entityId, Collections.singletonList(attributeIns)); + } else { + this.cachedScalePacket = null; + } + Object teamPacket = null; + if (config.glowColor != null) { + Object teamByColor = BukkitTeamManager.instance().getTeamByColor(config.glowColor); + if (teamByColor != null) { + teamPacket = FastNMS.INSTANCE.method$ClientboundSetPlayerTeamPacket$createMultiplePlayerPacket(teamByColor, List.of(this.uuid.toString()), true); + } + } + this.cachedTeamPacket = teamPacket; } @Override @@ -42,6 +64,12 @@ public class ArmorStandFurnitureElement implements FurnitureElement { player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundSetEquipmentPacket(this.entityId, List.of( Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, this.config.item(player, this.colorSource).getLiteralObject()) )), false); + if (this.cachedScalePacket != null) { + player.sendPacket(this.cachedScalePacket, false); + } + if (this.cachedTeamPacket != null) { + player.sendPacket(this.cachedTeamPacket, false); + } } @Override diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ArmorStandFurnitureElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ArmorStandFurnitureElementConfig.java index f24d95a48..ab2f09849 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ArmorStandFurnitureElementConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ArmorStandFurnitureElementConfig.java @@ -13,9 +13,12 @@ import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.item.ItemKeys; import net.momirealms.craftengine.core.item.data.FireworkExplosion; import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.LegacyChatFormatter; import net.momirealms.craftengine.core.util.ResourceConfigUtils; +import net.momirealms.craftengine.core.world.Glowing; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.joml.Vector3f; import java.util.ArrayList; @@ -24,7 +27,7 @@ import java.util.Map; import java.util.Optional; import java.util.function.Function; -public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig { +public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig, Glowing { public static final Factory FACTORY = new Factory(); public final Function> metadata; public final Key itemId; @@ -32,23 +35,31 @@ public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig< public final boolean applyDyedColor; public final Vector3f position; public final boolean small; + public final LegacyChatFormatter glowColor; public ArmorStandFurnitureElementConfig(Key itemId, float scale, Vector3f position, boolean applyDyedColor, - boolean small) { + boolean small, + LegacyChatFormatter glowColor) { this.position = position; this.applyDyedColor = applyDyedColor; this.small = small; this.scale = scale; this.itemId = itemId; + this.glowColor = glowColor; this.metadata = (player) -> { List dataValues = new ArrayList<>(2); - BaseEntityData.SharedFlags.addEntityData((byte) 0x20, dataValues); + if (glowColor != null) { + BaseEntityData.SharedFlags.addEntityData((byte) 0x60, dataValues); + } else { + BaseEntityData.SharedFlags.addEntityData((byte) 0x20, dataValues); + } if (small) { ArmorStandData.ArmorStandFlags.addEntityData((byte) 0x01, dataValues); } + return dataValues; }; } @@ -68,6 +79,12 @@ public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig< return Optional.ofNullable(wrappedItem).orElseGet(() -> BukkitItemManager.instance().createWrappedItem(ItemKeys.BARRIER, null)); } + @Nullable + @Override + public LegacyChatFormatter glowColor() { + return this.glowColor; + } + public float scale() { return scale; } @@ -102,7 +119,8 @@ public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig< ResourceConfigUtils.getAsFloat(arguments.getOrDefault("scale", 1f), "scale"), ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0f), "position"), ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("apply-dyed-color", true), "apply-dyed-color"), - ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("small", false), "small") + ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("small", false), "small"), + ResourceConfigUtils.getAsEnum(arguments.get("glow-color"), LegacyChatFormatter.class, null) ); } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomFurnitureHitbox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomFurnitureHitbox.java index da193062f..7e2caafed 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomFurnitureHitbox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomFurnitureHitbox.java @@ -4,12 +4,10 @@ import it.unimi.dsi.fastutil.ints.IntArrayList; import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MAttributeHolders; -import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.NetworkReflections; import net.momirealms.craftengine.core.entity.furniture.Collider; import net.momirealms.craftengine.core.entity.furniture.Furniture; import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitboxPart; import net.momirealms.craftengine.core.entity.player.Player; -import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.util.VersionHelper; import net.momirealms.craftengine.core.world.Vec3d; @@ -45,13 +43,9 @@ public class CustomFurnitureHitbox extends AbstractFurnitureHitBox { )); packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityId, config.cachedValues())); if (VersionHelper.isOrAbove1_20_5()) { - try { - Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer) (o) -> {}); - CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale()); - packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(entityId, Collections.singletonList(attributeInstance))); - } catch (ReflectiveOperationException e) { - CraftEngine.instance().logger().warn("Failed to apply scale attribute", e); - } + Object attributeIns = FastNMS.INSTANCE.constructor$AttributeInstance(MAttributeHolders.SCALE, (Consumer) (o) -> {}); + FastNMS.INSTANCE.method$AttributeInstance$setBaseValue(attributeIns, config.scale()); + packets.add(FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(entityId, Collections.singletonList(attributeIns))); } this.spawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets); this.part = new FurnitureHitboxPart(entityId, aabb, pos, false); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitbox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitbox.java index e5306701a..313e896b9 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitbox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitbox.java @@ -5,12 +5,10 @@ import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MAttributeHolders; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes; -import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.NetworkReflections; import net.momirealms.craftengine.core.entity.furniture.Collider; import net.momirealms.craftengine.core.entity.furniture.Furniture; import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitboxPart; import net.momirealms.craftengine.core.entity.player.Player; -import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.WorldPosition; import net.momirealms.craftengine.core.world.collision.AABB; @@ -43,13 +41,9 @@ public class HappyGhastFurnitureHitbox extends AbstractFurnitureHitBox { this.packets = new ArrayList<>(3); this.packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(this.entityId, config.cachedValues())); if (config.scale() != 1) { - try { - Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer) (o) -> {}); - CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale()); - this.packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(this.entityId, Collections.singletonList(attributeInstance))); - } catch (ReflectiveOperationException e) { - CraftEngine.instance().logger().warn("Failed to apply scale attribute", e); - } + Object attributeIns = FastNMS.INSTANCE.constructor$AttributeInstance(MAttributeHolders.SCALE, (Consumer) (o) -> {}); + FastNMS.INSTANCE.method$AttributeInstance$setBaseValue(attributeIns, config.scale()); + this.packets.add(FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(this.entityId, Collections.singletonList(attributeIns))); } this.packets.add(FastNMS.INSTANCE.constructor$ClientboundEntityPositionSyncPacket(this.entityId, this.pos.x, this.pos.y, this.pos.z, 0, position.yRot, false)); this.collider = createCollider(furniture.world(), this.pos, aabb, config.hardCollision(), config.blocksBuilding(), config.canBeHitByProjectile()); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitbox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitbox.java index ac88d288d..b55a65872 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitbox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitbox.java @@ -75,13 +75,9 @@ public class ShulkerFurnitureHitbox extends AbstractFurnitureHitBox { } } if (VersionHelper.isOrAbove1_20_5() && config.scale() != 1) { - try { - Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer) (o) -> {}); - CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale()); - packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(entityIds[1], Collections.singletonList(attributeInstance))); - } catch (ReflectiveOperationException e) { - CraftEngine.instance().logger().warn("Failed to apply scale attribute", e); - } + Object attributeIns = FastNMS.INSTANCE.constructor$AttributeInstance(MAttributeHolders.SCALE, (Consumer) (o) -> {}); + FastNMS.INSTANCE.method$AttributeInstance$setBaseValue(attributeIns, config.scale()); + packets.add(FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(this.entityIds[1], Collections.singletonList(attributeIns))); } config.spawner().accept(entityIds, position.world(), x, y, z, yaw, offset, packets::add, colliders::add, parts::add); this.parts = parts; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/reflection/minecraft/CoreReflections.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/reflection/minecraft/CoreReflections.java index 661b445e0..c1f11650e 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/reflection/minecraft/CoreReflections.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/reflection/minecraft/CoreReflections.java @@ -24,7 +24,6 @@ import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiConsumer; -import java.util.function.Consumer; import java.util.function.Function; import static java.util.Objects.requireNonNull; @@ -2863,12 +2862,12 @@ public final class CoreReflections { ); // 1.20.5+ - public static final Constructor constructor$AttributeInstance = - ReflectionUtils.getConstructor(clazz$AttributeInstance, clazz$Holder, Consumer.class); +// public static final Constructor constructor$AttributeInstance = +// ReflectionUtils.getConstructor(clazz$AttributeInstance, clazz$Holder, Consumer.class); - public static final Method method$AttributeInstance$setBaseValue = requireNonNull( - ReflectionUtils.getMethod(clazz$AttributeInstance, void.class, double.class) - ); +// public static final Method method$AttributeInstance$setBaseValue = requireNonNull( +// ReflectionUtils.getMethod(clazz$AttributeInstance, void.class, double.class) +// ); public static final Class clazz$Rotation = requireNonNull( BukkitReflectionUtils.findReobfOrMojmapClass( diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java index b29efe890..d9ebbbe69 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java @@ -811,8 +811,7 @@ public class BukkitServerPlayer extends Player { if (VersionHelper.isOrAbove1_20_5()) { Object serverPlayer = serverPlayer(); Object attributeInstance = CoreReflections.methodHandle$ServerPlayer$getAttributeMethod.invokeExact(serverPlayer, MAttributeHolders.BLOCK_BREAK_SPEED); - Object newPacket = NetworkReflections.methodHandle$ClientboundUpdateAttributesPacket0Constructor.invokeExact(entityId(), (List) Lists.newArrayList(attributeInstance)); - sendPacket(newPacket, true); + sendPacket(FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(entityId(), Lists.newArrayList(attributeInstance)), true); } else { resetEffect(MMobEffects.MINING_FATIGUE); resetEffect(MMobEffects.HASTE); diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/AbstractBlockManager.java b/core/src/main/java/net/momirealms/craftengine/core/block/AbstractBlockManager.java index 9f620cd82..cc1b2fff5 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/AbstractBlockManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/AbstractBlockManager.java @@ -39,6 +39,7 @@ import net.momirealms.craftengine.core.registry.BuiltInRegistries; import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.registry.WritableRegistry; import net.momirealms.craftengine.core.util.*; +import net.momirealms.craftengine.core.world.Glowing; import net.momirealms.craftengine.core.world.collision.AABB; import net.momirealms.sparrow.nbt.CompoundTag; import org.incendo.cloud.suggestion.Suggestion; @@ -744,6 +745,11 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem if (arguments == null) return Optional.empty(); List> blockEntityElementConfigs = ResourceConfigUtils.parseConfigAsList(arguments, BlockEntityElementConfigs::fromMap); if (blockEntityElementConfigs.isEmpty()) return Optional.empty(); + for (BlockEntityElementConfig blockEntityElementConfig : blockEntityElementConfigs) { + if (blockEntityElementConfig instanceof Glowing glowing && glowing.glowColor() != null) { + AbstractBlockManager.this.plugin.teamManager().setColorInUse(glowing.glowColor()); + } + } return Optional.of(blockEntityElementConfigs.toArray(new BlockEntityElementConfig[0])); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/AbstractFurnitureManager.java b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/AbstractFurnitureManager.java index d439e8ea3..3bf2300a1 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/AbstractFurnitureManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/AbstractFurnitureManager.java @@ -19,6 +19,7 @@ import net.momirealms.craftengine.core.plugin.entityculling.CullingData; import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.plugin.scheduler.SchedulerTask; import net.momirealms.craftengine.core.util.*; +import net.momirealms.craftengine.core.world.Glowing; import org.incendo.cloud.suggestion.Suggestion; import org.joml.Vector3f; @@ -219,6 +220,13 @@ public abstract class AbstractFurnitureManager implements FurnitureManager { Optional optionalLootSpawnOffset = Optional.ofNullable(variantArguments.get("loot-spawn-offset")).map(it -> ResourceConfigUtils.getAsVector3f(it, "loot-spawn-offset")); List> elements = ResourceConfigUtils.parseConfigAsList(variantArguments.get("elements"), FurnitureElementConfigs::fromMap); + // 收集颜色 + for (FurnitureElementConfig element : elements) { + if (element instanceof Glowing glowing && glowing.glowColor() != null) { + AbstractFurnitureManager.this.plugin.teamManager().setColorInUse(glowing.glowColor()); + } + } + // 外部模型 Optional externalModel; if (variantArguments.containsKey("model-engine")) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/world/Glowing.java b/core/src/main/java/net/momirealms/craftengine/core/world/Glowing.java new file mode 100644 index 000000000..b237e34b5 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/world/Glowing.java @@ -0,0 +1,10 @@ +package net.momirealms.craftengine.core.world; + +import net.momirealms.craftengine.core.util.LegacyChatFormatter; +import org.jetbrains.annotations.Nullable; + +public interface Glowing { + + @Nullable + LegacyChatFormatter glowColor(); +} diff --git a/gradle.properties b/gradle.properties index 2a2f5f0f6..1488dee0e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -48,7 +48,7 @@ byte_buddy_version=1.18.1 ahocorasick_version=0.6.3 snake_yaml_version=2.5 anti_grief_version=1.0.5 -nms_helper_version=1.0.146 +nms_helper_version=1.0.148 evalex_version=3.5.0 reactive_streams_version=1.0.4 amazon_awssdk_version=2.38.7