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

完善家具渲染元素

This commit is contained in:
XiaoMoMi
2025-12-06 23:02:56 +08:00
parent adf34c860f
commit 283d5e86c1
16 changed files with 182 additions and 81 deletions

View File

@@ -4,21 +4,29 @@ import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntList;
import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections; 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.MEntityTypes;
import net.momirealms.craftengine.bukkit.world.score.BukkitTeamManager;
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement; import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
import net.momirealms.craftengine.core.entity.player.Player; import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.world.BlockPos; import net.momirealms.craftengine.core.world.BlockPos;
import org.joml.Vector3f; import org.joml.Vector3f;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
public class ArmorStandBlockEntityElement implements BlockEntityElement { public class ArmorStandBlockEntityElement implements BlockEntityElement {
public final ArmorStandBlockEntityElementConfig config; public final ArmorStandBlockEntityElementConfig config;
public final Object cachedSpawnPacket; public final Object cachedSpawnPacket;
public final Object cachedDespawnPacket; public final Object cachedDespawnPacket;
public final Object cachedUpdatePosPacket; public final Object cachedUpdatePosPacket;
public final Object cachedScalePacket;
public final Object cachedTeamPacket;
public final int entityId; public final int entityId;
public final UUID uuid = UUID.randomUUID();
public ArmorStandBlockEntityElement(ArmorStandBlockEntityElementConfig config, BlockPos pos) { public ArmorStandBlockEntityElement(ArmorStandBlockEntityElementConfig config, BlockPos pos) {
this(config, pos, CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet(), false); 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) { public ArmorStandBlockEntityElement(ArmorStandBlockEntityElementConfig config, BlockPos pos, int entityId, boolean posChanged) {
Vector3f position = config.position(); Vector3f position = config.position();
this.cachedSpawnPacket = FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( 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() config.xRot(), config.yRot(), MEntityTypes.ARMOR_STAND, 0, CoreReflections.instance$Vec3$Zero, config.yRot()
); );
this.config = config; this.config = config;
this.cachedDespawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(IntList.of(entityId)); this.cachedDespawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(IntList.of(entityId));
this.entityId = 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; 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 @Override
@@ -47,6 +70,12 @@ public class ArmorStandBlockEntityElement implements BlockEntityElement {
player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundSetEquipmentPacket(this.entityId, List.of( player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundSetEquipmentPacket(this.entityId, List.of(
Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, this.config.item(player).getLiteralObject()) Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, this.config.item(player).getLiteralObject())
)), false); )), false);
if (this.cachedDespawnPacket != null) {
player.sendPacket(this.cachedDespawnPacket, false);
}
if (this.cachedTeamPacket != null) {
player.sendPacket(this.cachedTeamPacket, false);
}
} }
@Override @Override

View File

@@ -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.Item;
import net.momirealms.craftengine.core.item.ItemKeys; import net.momirealms.craftengine.core.item.ItemKeys;
import net.momirealms.craftengine.core.util.Key; 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.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.world.BlockPos; import net.momirealms.craftengine.core.world.BlockPos;
import net.momirealms.craftengine.core.world.Glowing;
import net.momirealms.craftengine.core.world.World; import net.momirealms.craftengine.core.world.World;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f; import org.joml.Vector3f;
import java.util.ArrayList; import java.util.ArrayList;
@@ -21,23 +24,26 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
public class ArmorStandBlockEntityElementConfig implements BlockEntityElementConfig<ArmorStandBlockEntityElement> { public class ArmorStandBlockEntityElementConfig implements BlockEntityElementConfig<ArmorStandBlockEntityElement>, Glowing {
public static final Factory FACTORY = new Factory(); public static final Factory FACTORY = new Factory();
private final Function<Player, List<Object>> lazyMetadataPacket; public final Function<Player, List<Object>> lazyMetadataPacket;
private final Key itemId; public final Key itemId;
private final float scale; public final float scale;
private final Vector3f position; public final Vector3f position;
private final float xRot; public final float xRot;
private final float yRot; public final float yRot;
private final boolean small; public final boolean small;
public final LegacyChatFormatter glowColor;
public ArmorStandBlockEntityElementConfig(Key itemId, public ArmorStandBlockEntityElementConfig(Key itemId,
float scale, float scale,
Vector3f position, Vector3f position,
float xRot, float xRot,
float yRot, float yRot,
boolean small) { boolean small,
LegacyChatFormatter glowColor) {
this.itemId = itemId; this.itemId = itemId;
this.glowColor = glowColor;
this.scale = scale; this.scale = scale;
this.position = position; this.position = position;
this.xRot = xRot; this.xRot = xRot;
@@ -45,7 +51,11 @@ public class ArmorStandBlockEntityElementConfig implements BlockEntityElementCon
this.small = small; this.small = small;
this.lazyMetadataPacket = player -> { this.lazyMetadataPacket = player -> {
List<Object> dataValues = new ArrayList<>(2); List<Object> 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) { if (small) {
ArmorStandData.ArmorStandFlags.addEntityData((byte) 0x01, dataValues); ArmorStandData.ArmorStandFlags.addEntityData((byte) 0x01, dataValues);
} }
@@ -53,6 +63,12 @@ public class ArmorStandBlockEntityElementConfig implements BlockEntityElementCon
}; };
} }
@Nullable
@Override
public LegacyChatFormatter glowColor() {
return this.glowColor;
}
@Override @Override
public ArmorStandBlockEntityElement create(World world, BlockPos pos) { public ArmorStandBlockEntityElement create(World world, BlockPos pos) {
return new ArmorStandBlockEntityElement(this, pos); return new ArmorStandBlockEntityElement(this, pos);
@@ -60,6 +76,9 @@ public class ArmorStandBlockEntityElementConfig implements BlockEntityElementCon
@Override @Override
public ArmorStandBlockEntityElement create(World world, BlockPos pos, ArmorStandBlockEntityElement previous) { 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, return new ArmorStandBlockEntityElement(this, pos, previous.entityId,
previous.config.yRot != this.yRot || previous.config.yRot != this.yRot ||
previous.config.xRot != this.xRot || previous.config.xRot != this.xRot ||
@@ -129,7 +148,8 @@ public class ArmorStandBlockEntityElementConfig implements BlockEntityElementCon
ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0.5f), "position"), ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0.5f), "position"),
ResourceConfigUtils.getAsFloat(arguments.getOrDefault("pitch", 0f), "pitch"), ResourceConfigUtils.getAsFloat(arguments.getOrDefault("pitch", 0f), "pitch"),
ResourceConfigUtils.getAsFloat(arguments.getOrDefault("yaw", 0f), "yaw"), 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)
); );
} }
} }

View File

@@ -22,9 +22,9 @@ import java.util.function.Function;
public class ItemBlockEntityElementConfig implements BlockEntityElementConfig<ItemBlockEntityElement> { public class ItemBlockEntityElementConfig implements BlockEntityElementConfig<ItemBlockEntityElement> {
public static final Factory FACTORY = new Factory(); public static final Factory FACTORY = new Factory();
private final Function<Player, List<Object>> lazyMetadataPacket; public final Function<Player, List<Object>> lazyMetadataPacket;
private final Key itemId; public final Key itemId;
private final Vector3f position; public final Vector3f position;
public ItemBlockEntityElementConfig(Key itemId, Vector3f position) { public ItemBlockEntityElementConfig(Key itemId, Vector3f position) {
this.itemId = itemId; this.itemId = itemId;

View File

@@ -28,22 +28,22 @@ import java.util.function.Function;
public class ItemDisplayBlockEntityElementConfig implements BlockEntityElementConfig<ItemDisplayBlockEntityElement> { public class ItemDisplayBlockEntityElementConfig implements BlockEntityElementConfig<ItemDisplayBlockEntityElement> {
public static final Factory FACTORY = new Factory(); public static final Factory FACTORY = new Factory();
private final Function<Player, List<Object>> lazyMetadataPacket; public final Function<Player, List<Object>> lazyMetadataPacket;
private final Key itemId; public final Key itemId;
private final Vector3f scale; public final Vector3f scale;
private final Vector3f position; public final Vector3f position;
private final Vector3f translation; public final Vector3f translation;
private final float xRot; public final float xRot;
private final float yRot; public final float yRot;
private final Quaternionf rotation; public final Quaternionf rotation;
private final ItemDisplayContext displayContext; public final ItemDisplayContext displayContext;
private final Billboard billboard; public final Billboard billboard;
private final float shadowRadius; public final float shadowRadius;
private final float shadowStrength; public final float shadowStrength;
private final Color glowColor; public final Color glowColor;
private final int blockLight; public final int blockLight;
private final int skyLight; public final int skyLight;
private final float viewRange; public final float viewRange;
public ItemDisplayBlockEntityElementConfig(Key itemId, public ItemDisplayBlockEntityElementConfig(Key itemId,
Vector3f scale, Vector3f scale,

View File

@@ -24,15 +24,15 @@ import java.util.function.Function;
public class TextDisplayBlockEntityElementConfig implements BlockEntityElementConfig<TextDisplayBlockEntityElement> { public class TextDisplayBlockEntityElementConfig implements BlockEntityElementConfig<TextDisplayBlockEntityElement> {
public static final Factory FACTORY = new Factory(); public static final Factory FACTORY = new Factory();
private final Function<Player, List<Object>> lazyMetadataPacket; public final Function<Player, List<Object>> lazyMetadataPacket;
private final String text; public final String text;
private final Vector3f scale; public final Vector3f scale;
private final Vector3f position; public final Vector3f position;
private final Vector3f translation; public final Vector3f translation;
private final float xRot; public final float xRot;
private final float yRot; public final float yRot;
private final Quaternionf rotation; public final Quaternionf rotation;
private final Billboard billboard; public final Billboard billboard;
public final Color glowColor; public final Color glowColor;
public final int blockLight; public final int blockLight;
public final int skyLight; public final int skyLight;

View File

@@ -4,24 +4,31 @@ import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntList;
import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections; 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.MEntityTypes;
import net.momirealms.craftengine.bukkit.world.score.BukkitTeamManager;
import net.momirealms.craftengine.core.entity.furniture.Furniture; import net.momirealms.craftengine.core.entity.furniture.Furniture;
import net.momirealms.craftengine.core.entity.furniture.FurnitureColorSource; import net.momirealms.craftengine.core.entity.furniture.FurnitureColorSource;
import net.momirealms.craftengine.core.entity.furniture.element.FurnitureElement; import net.momirealms.craftengine.core.entity.furniture.element.FurnitureElement;
import net.momirealms.craftengine.core.entity.player.Player; 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.Vec3d;
import net.momirealms.craftengine.core.world.WorldPosition; import net.momirealms.craftengine.core.world.WorldPosition;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
public class ArmorStandFurnitureElement implements FurnitureElement { public class ArmorStandFurnitureElement implements FurnitureElement {
private final ArmorStandFurnitureElementConfig config; private final ArmorStandFurnitureElementConfig config;
public final int entityId;
private final FurnitureColorSource colorSource; private final FurnitureColorSource colorSource;
public final Object cachedSpawnPacket; public final Object cachedSpawnPacket;
public final Object cachedDespawnPacket; 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) { public ArmorStandFurnitureElement(Furniture furniture, ArmorStandFurnitureElementConfig config) {
this.config = config; this.config = config;
@@ -29,11 +36,26 @@ public class ArmorStandFurnitureElement implements FurnitureElement {
WorldPosition furniturePos = furniture.position(); WorldPosition furniturePos = furniture.position();
Vec3d position = Furniture.getRelativePosition(furniturePos, config.position()); Vec3d position = Furniture.getRelativePosition(furniturePos, config.position());
this.cachedSpawnPacket = FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( 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 furniturePos.xRot, furniturePos.yRot, MEntityTypes.ARMOR_STAND, 0, CoreReflections.instance$Vec3$Zero, furniturePos.yRot
); );
this.colorSource = furniture.dataAccessor.getColorSource(); 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 @Override
@@ -42,6 +64,12 @@ public class ArmorStandFurnitureElement implements FurnitureElement {
player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundSetEquipmentPacket(this.entityId, List.of( player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundSetEquipmentPacket(this.entityId, List.of(
Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, this.config.item(player, this.colorSource).getLiteralObject()) Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, this.config.item(player, this.colorSource).getLiteralObject())
)), false); )), false);
if (this.cachedScalePacket != null) {
player.sendPacket(this.cachedScalePacket, false);
}
if (this.cachedTeamPacket != null) {
player.sendPacket(this.cachedTeamPacket, false);
}
} }
@Override @Override

View File

@@ -13,9 +13,12 @@ import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.ItemKeys; import net.momirealms.craftengine.core.item.ItemKeys;
import net.momirealms.craftengine.core.item.data.FireworkExplosion; import net.momirealms.craftengine.core.item.data.FireworkExplosion;
import net.momirealms.craftengine.core.util.Key; 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.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.world.Glowing;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f; import org.joml.Vector3f;
import java.util.ArrayList; import java.util.ArrayList;
@@ -24,7 +27,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig<ArmorStandFurnitureElement> { public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig<ArmorStandFurnitureElement>, Glowing {
public static final Factory FACTORY = new Factory(); public static final Factory FACTORY = new Factory();
public final Function<Player, List<Object>> metadata; public final Function<Player, List<Object>> metadata;
public final Key itemId; public final Key itemId;
@@ -32,23 +35,31 @@ public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig<
public final boolean applyDyedColor; public final boolean applyDyedColor;
public final Vector3f position; public final Vector3f position;
public final boolean small; public final boolean small;
public final LegacyChatFormatter glowColor;
public ArmorStandFurnitureElementConfig(Key itemId, public ArmorStandFurnitureElementConfig(Key itemId,
float scale, float scale,
Vector3f position, Vector3f position,
boolean applyDyedColor, boolean applyDyedColor,
boolean small) { boolean small,
LegacyChatFormatter glowColor) {
this.position = position; this.position = position;
this.applyDyedColor = applyDyedColor; this.applyDyedColor = applyDyedColor;
this.small = small; this.small = small;
this.scale = scale; this.scale = scale;
this.itemId = itemId; this.itemId = itemId;
this.glowColor = glowColor;
this.metadata = (player) -> { this.metadata = (player) -> {
List<Object> dataValues = new ArrayList<>(2); List<Object> 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) { if (small) {
ArmorStandData.ArmorStandFlags.addEntityData((byte) 0x01, dataValues); ArmorStandData.ArmorStandFlags.addEntityData((byte) 0x01, dataValues);
} }
return dataValues; return dataValues;
}; };
} }
@@ -68,6 +79,12 @@ public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig<
return Optional.ofNullable(wrappedItem).orElseGet(() -> BukkitItemManager.instance().createWrappedItem(ItemKeys.BARRIER, null)); return Optional.ofNullable(wrappedItem).orElseGet(() -> BukkitItemManager.instance().createWrappedItem(ItemKeys.BARRIER, null));
} }
@Nullable
@Override
public LegacyChatFormatter glowColor() {
return this.glowColor;
}
public float scale() { public float scale() {
return scale; return scale;
} }
@@ -102,7 +119,8 @@ public class ArmorStandFurnitureElementConfig implements FurnitureElementConfig<
ResourceConfigUtils.getAsFloat(arguments.getOrDefault("scale", 1f), "scale"), ResourceConfigUtils.getAsFloat(arguments.getOrDefault("scale", 1f), "scale"),
ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0f), "position"), ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0f), "position"),
ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("apply-dyed-color", true), "apply-dyed-color"), 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)
); );
} }
} }

View File

@@ -4,12 +4,10 @@ import it.unimi.dsi.fastutil.ints.IntArrayList;
import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections; 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.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.Collider;
import net.momirealms.craftengine.core.entity.furniture.Furniture; import net.momirealms.craftengine.core.entity.furniture.Furniture;
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitboxPart; import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitboxPart;
import net.momirealms.craftengine.core.entity.player.Player; 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.MiscUtils;
import net.momirealms.craftengine.core.util.VersionHelper; import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.world.Vec3d; 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())); packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityId, config.cachedValues()));
if (VersionHelper.isOrAbove1_20_5()) { if (VersionHelper.isOrAbove1_20_5()) {
try { Object attributeIns = FastNMS.INSTANCE.constructor$AttributeInstance(MAttributeHolders.SCALE, (Consumer<?>) (o) -> {});
Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer<?>) (o) -> {}); FastNMS.INSTANCE.method$AttributeInstance$setBaseValue(attributeIns, config.scale());
CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale()); packets.add(FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(entityId, Collections.singletonList(attributeIns)));
packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(entityId, Collections.singletonList(attributeInstance)));
} catch (ReflectiveOperationException e) {
CraftEngine.instance().logger().warn("Failed to apply scale attribute", e);
}
} }
this.spawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets); this.spawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets);
this.part = new FurnitureHitboxPart(entityId, aabb, pos, false); this.part = new FurnitureHitboxPart(entityId, aabb, pos, false);

View File

@@ -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.CoreReflections;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MAttributeHolders; 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.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.Collider;
import net.momirealms.craftengine.core.entity.furniture.Furniture; import net.momirealms.craftengine.core.entity.furniture.Furniture;
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitboxPart; import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitboxPart;
import net.momirealms.craftengine.core.entity.player.Player; 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.Vec3d;
import net.momirealms.craftengine.core.world.WorldPosition; import net.momirealms.craftengine.core.world.WorldPosition;
import net.momirealms.craftengine.core.world.collision.AABB; import net.momirealms.craftengine.core.world.collision.AABB;
@@ -43,13 +41,9 @@ public class HappyGhastFurnitureHitbox extends AbstractFurnitureHitBox {
this.packets = new ArrayList<>(3); this.packets = new ArrayList<>(3);
this.packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(this.entityId, config.cachedValues())); this.packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(this.entityId, config.cachedValues()));
if (config.scale() != 1) { if (config.scale() != 1) {
try { Object attributeIns = FastNMS.INSTANCE.constructor$AttributeInstance(MAttributeHolders.SCALE, (Consumer<?>) (o) -> {});
Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer<?>) (o) -> {}); FastNMS.INSTANCE.method$AttributeInstance$setBaseValue(attributeIns, config.scale());
CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale()); this.packets.add(FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(this.entityId, Collections.singletonList(attributeIns)));
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);
}
} }
this.packets.add(FastNMS.INSTANCE.constructor$ClientboundEntityPositionSyncPacket(this.entityId, this.pos.x, this.pos.y, this.pos.z, 0, position.yRot, false)); 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()); this.collider = createCollider(furniture.world(), this.pos, aabb, config.hardCollision(), config.blocksBuilding(), config.canBeHitByProjectile());

View File

@@ -75,13 +75,9 @@ public class ShulkerFurnitureHitbox extends AbstractFurnitureHitBox {
} }
} }
if (VersionHelper.isOrAbove1_20_5() && config.scale() != 1) { if (VersionHelper.isOrAbove1_20_5() && config.scale() != 1) {
try { Object attributeIns = FastNMS.INSTANCE.constructor$AttributeInstance(MAttributeHolders.SCALE, (Consumer<?>) (o) -> {});
Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer<?>) (o) -> {}); FastNMS.INSTANCE.method$AttributeInstance$setBaseValue(attributeIns, config.scale());
CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale()); packets.add(FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(this.entityIds[1], Collections.singletonList(attributeIns)));
packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(entityIds[1], Collections.singletonList(attributeInstance)));
} catch (ReflectiveOperationException e) {
CraftEngine.instance().logger().warn("Failed to apply scale attribute", e);
}
} }
config.spawner().accept(entityIds, position.world(), x, y, z, yaw, offset, packets::add, colliders::add, parts::add); config.spawner().accept(entityIds, position.world(), x, y, z, yaw, offset, packets::add, colliders::add, parts::add);
this.parts = parts; this.parts = parts;

View File

@@ -24,7 +24,6 @@ import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
@@ -2863,12 +2862,12 @@ public final class CoreReflections {
); );
// 1.20.5+ // 1.20.5+
public static final Constructor<?> constructor$AttributeInstance = // public static final Constructor<?> constructor$AttributeInstance =
ReflectionUtils.getConstructor(clazz$AttributeInstance, clazz$Holder, Consumer.class); // ReflectionUtils.getConstructor(clazz$AttributeInstance, clazz$Holder, Consumer.class);
public static final Method method$AttributeInstance$setBaseValue = requireNonNull( // public static final Method method$AttributeInstance$setBaseValue = requireNonNull(
ReflectionUtils.getMethod(clazz$AttributeInstance, void.class, double.class) // ReflectionUtils.getMethod(clazz$AttributeInstance, void.class, double.class)
); // );
public static final Class<?> clazz$Rotation = requireNonNull( public static final Class<?> clazz$Rotation = requireNonNull(
BukkitReflectionUtils.findReobfOrMojmapClass( BukkitReflectionUtils.findReobfOrMojmapClass(

View File

@@ -811,8 +811,7 @@ public class BukkitServerPlayer extends Player {
if (VersionHelper.isOrAbove1_20_5()) { if (VersionHelper.isOrAbove1_20_5()) {
Object serverPlayer = serverPlayer(); Object serverPlayer = serverPlayer();
Object attributeInstance = CoreReflections.methodHandle$ServerPlayer$getAttributeMethod.invokeExact(serverPlayer, MAttributeHolders.BLOCK_BREAK_SPEED); Object attributeInstance = CoreReflections.methodHandle$ServerPlayer$getAttributeMethod.invokeExact(serverPlayer, MAttributeHolders.BLOCK_BREAK_SPEED);
Object newPacket = NetworkReflections.methodHandle$ClientboundUpdateAttributesPacket0Constructor.invokeExact(entityId(), (List<?>) Lists.newArrayList(attributeInstance)); sendPacket(FastNMS.INSTANCE.constructor$ClientboundUpdateAttributesPacket(entityId(), Lists.newArrayList(attributeInstance)), true);
sendPacket(newPacket, true);
} else { } else {
resetEffect(MMobEffects.MINING_FATIGUE); resetEffect(MMobEffects.MINING_FATIGUE);
resetEffect(MMobEffects.HASTE); resetEffect(MMobEffects.HASTE);

View File

@@ -39,6 +39,7 @@ import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.WritableRegistry; import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.*; import net.momirealms.craftengine.core.util.*;
import net.momirealms.craftengine.core.world.Glowing;
import net.momirealms.craftengine.core.world.collision.AABB; import net.momirealms.craftengine.core.world.collision.AABB;
import net.momirealms.sparrow.nbt.CompoundTag; import net.momirealms.sparrow.nbt.CompoundTag;
import org.incendo.cloud.suggestion.Suggestion; import org.incendo.cloud.suggestion.Suggestion;
@@ -744,6 +745,11 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
if (arguments == null) return Optional.empty(); if (arguments == null) return Optional.empty();
List<BlockEntityElementConfig<? extends BlockEntityElement>> blockEntityElementConfigs = ResourceConfigUtils.parseConfigAsList(arguments, BlockEntityElementConfigs::fromMap); List<BlockEntityElementConfig<? extends BlockEntityElement>> blockEntityElementConfigs = ResourceConfigUtils.parseConfigAsList(arguments, BlockEntityElementConfigs::fromMap);
if (blockEntityElementConfigs.isEmpty()) return Optional.empty(); if (blockEntityElementConfigs.isEmpty()) return Optional.empty();
for (BlockEntityElementConfig<? extends BlockEntityElement> 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])); return Optional.of(blockEntityElementConfigs.toArray(new BlockEntityElementConfig[0]));
} }

View File

@@ -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.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.scheduler.SchedulerTask; import net.momirealms.craftengine.core.plugin.scheduler.SchedulerTask;
import net.momirealms.craftengine.core.util.*; import net.momirealms.craftengine.core.util.*;
import net.momirealms.craftengine.core.world.Glowing;
import org.incendo.cloud.suggestion.Suggestion; import org.incendo.cloud.suggestion.Suggestion;
import org.joml.Vector3f; import org.joml.Vector3f;
@@ -219,6 +220,13 @@ public abstract class AbstractFurnitureManager implements FurnitureManager {
Optional<Vector3f> optionalLootSpawnOffset = Optional.ofNullable(variantArguments.get("loot-spawn-offset")).map(it -> ResourceConfigUtils.getAsVector3f(it, "loot-spawn-offset")); Optional<Vector3f> optionalLootSpawnOffset = Optional.ofNullable(variantArguments.get("loot-spawn-offset")).map(it -> ResourceConfigUtils.getAsVector3f(it, "loot-spawn-offset"));
List<FurnitureElementConfig<?>> elements = ResourceConfigUtils.parseConfigAsList(variantArguments.get("elements"), FurnitureElementConfigs::fromMap); List<FurnitureElementConfig<?>> 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> externalModel; Optional<ExternalModel> externalModel;
if (variantArguments.containsKey("model-engine")) { if (variantArguments.containsKey("model-engine")) {

View File

@@ -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();
}

View File

@@ -48,7 +48,7 @@ byte_buddy_version=1.18.1
ahocorasick_version=0.6.3 ahocorasick_version=0.6.3
snake_yaml_version=2.5 snake_yaml_version=2.5
anti_grief_version=1.0.5 anti_grief_version=1.0.5
nms_helper_version=1.0.146 nms_helper_version=1.0.148
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.38.7 amazon_awssdk_version=2.38.7