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 20:14:47 +08:00
parent 9f77791ed2
commit 1566ac89c9
25 changed files with 339 additions and 91 deletions

View File

@@ -9,8 +9,6 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
import static java.util.Objects.requireNonNull;
public class MMOItemsSource implements ExternalItemSource<ItemStack> {

View File

@@ -1,14 +1,17 @@
package net.momirealms.craftengine.bukkit.api;
import net.momirealms.craftengine.bukkit.entity.BukkitEntity;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
import net.momirealms.craftengine.bukkit.world.BukkitExistingBlock;
import net.momirealms.craftengine.bukkit.world.BukkitWorld;
import net.momirealms.craftengine.core.item.Item;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public final class BukkitAdaptors {
@@ -62,4 +65,15 @@ public final class BukkitAdaptors {
public static BukkitExistingBlock adapt(@NotNull final Block block) {
return new BukkitExistingBlock(block);
}
/**
* Adapts a Bukkit ItemStack to a CraftEngine wrapped item
*
* @param item the Bukkit ItemStack to adapt, must not be null
* @return a non-null Item instance wrapping the provided item
*/
@NotNull
public static Item<ItemStack> adapt(@NotNull final ItemStack item) {
return BukkitItemManager.instance().wrap(item);
}
}

View File

@@ -0,0 +1,69 @@
package net.momirealms.craftengine.bukkit.block.entity.renderer.element;
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.MEntityTypes;
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.world.BlockPos;
import org.joml.Vector3f;
import java.util.List;
import java.util.UUID;
public class ArmorStandBlockEntityElement implements BlockEntityElement {
public final ArmorStandBlockEntityElementConfig config;
public final Object cachedSpawnPacket;
public final Object cachedDespawnPacket;
public final Object cachedUpdatePosPacket;
public final int entityId;
public ArmorStandBlockEntityElement(ArmorStandBlockEntityElementConfig config, BlockPos pos) {
this(config, pos, CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet(), false);
}
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,
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;
}
@Override
public void hide(Player player) {
player.sendPacket(this.cachedDespawnPacket, false);
}
@Override
public void show(Player player) {
player.sendPackets(List.of(this.cachedSpawnPacket, FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(this.entityId, this.config.metadataValues(player))), false);
player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundSetEquipmentPacket(this.entityId, List.of(
Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, this.config.item(player).getLiteralObject())
)), false);
}
@Override
public void transform(Player player) {
if (this.cachedUpdatePosPacket != null) {
player.sendPackets(List.of(
this.cachedUpdatePosPacket,
FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(this.entityId, this.config.metadataValues(player)),
FastNMS.INSTANCE.constructor$ClientboundSetEquipmentPacket(this.entityId, List.of(
Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, this.config.item(player).getLiteralObject())
))
), false);
} else {
player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(this.entityId, this.config.metadataValues(player)), false);
player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundSetEquipmentPacket(this.entityId, List.of(
Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, this.config.item(player).getLiteralObject())
)), false);
}
}
}

View File

@@ -0,0 +1,130 @@
package net.momirealms.craftengine.bukkit.block.entity.renderer.element;
import com.google.common.base.Objects;
import net.momirealms.craftengine.bukkit.entity.data.ArmorStandData;
import net.momirealms.craftengine.bukkit.entity.data.BaseEntityData;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfig;
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigFactory;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.world.BlockPos;
import net.momirealms.craftengine.core.world.World;
import org.joml.Vector3f;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
public class ArmorStandBlockEntityElementConfig implements BlockEntityElementConfig<ArmorStandBlockEntityElement> {
public static final Factory FACTORY = new Factory();
private final Function<Player, List<Object>> lazyMetadataPacket;
private final Function<Player, Item<?>> item;
private final Vector3f scale;
private final Vector3f position;
private final float xRot;
private final float yRot;
private final boolean small;
public ArmorStandBlockEntityElementConfig(Function<Player, Item<?>> item,
Vector3f scale,
Vector3f position,
float xRot,
float yRot,
boolean small) {
this.item = item;
this.scale = scale;
this.position = position;
this.xRot = xRot;
this.yRot = yRot;
this.small = small;
this.lazyMetadataPacket = player -> {
List<Object> dataValues = new ArrayList<>(2);
BaseEntityData.SharedFlags.addEntityData((byte) 0x20, dataValues);
if (small) {
ArmorStandData.ArmorStandFlags.addEntityData((byte) 0x01, dataValues);
}
return dataValues;
};
}
@Override
public ArmorStandBlockEntityElement create(World world, BlockPos pos) {
return new ArmorStandBlockEntityElement(this, pos);
}
@Override
public ArmorStandBlockEntityElement create(World world, BlockPos pos, ArmorStandBlockEntityElement previous) {
return new ArmorStandBlockEntityElement(this, pos, previous.entityId,
previous.config.yRot != this.yRot ||
previous.config.xRot != this.xRot ||
!previous.config.position.equals(this.position)
);
}
@Override
public ArmorStandBlockEntityElement createExact(World world, BlockPos pos, ArmorStandBlockEntityElement previous) {
if (!previous.config.isSamePosition(this)) {
return null;
}
return new ArmorStandBlockEntityElement(this, pos, previous.entityId, false);
}
@Override
public Class<ArmorStandBlockEntityElement> elementClass() {
return ArmorStandBlockEntityElement.class;
}
public Item<?> item(Player player) {
return this.item.apply(player);
}
public Vector3f scale() {
return this.scale;
}
public Vector3f position() {
return this.position;
}
public float yRot() {
return this.yRot;
}
public float xRot() {
return this.xRot;
}
public boolean small() {
return this.small;
}
public List<Object> metadataValues(Player player) {
return this.lazyMetadataPacket.apply(player);
}
public boolean isSamePosition(ArmorStandBlockEntityElementConfig that) {
return Float.compare(xRot, that.xRot) == 0 &&
Float.compare(yRot, that.yRot) == 0 &&
Objects.equal(position, that.position);
}
public static class Factory implements BlockEntityElementConfigFactory<ArmorStandBlockEntityElement> {
@Override
public ArmorStandBlockEntityElementConfig create(Map<String, Object> arguments) {
Key itemId = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("item"), "warning.config.block.state.entity_renderer.armor_stand.missing_item"));
return new ArmorStandBlockEntityElementConfig(
player -> BukkitItemManager.instance().createWrappedItem(itemId, player),
ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("scale", 1f), "scale"),
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")
);
}
}
}

View File

@@ -8,6 +8,7 @@ public class BukkitBlockEntityElementConfigs extends BlockEntityElementConfigs {
register(ITEM_DISPLAY, ItemDisplayBlockEntityElementConfig.FACTORY);
register(TEXT_DISPLAY, TextDisplayBlockEntityElementConfig.FACTORY);
register(ITEM, ItemBlockEntityElementConfig.FACTORY);
register(ARMOR_STAND, ArmorStandBlockEntityElementConfig.FACTORY);
}
private BukkitBlockEntityElementConfigs() {}

View File

@@ -46,7 +46,7 @@ public class ItemBlockEntityElementConfig implements BlockEntityElementConfig<It
@Override
public ItemBlockEntityElement createExact(World world, BlockPos pos, ItemBlockEntityElement previous) {
if (!previous.config.equals(this)) {
if (!previous.config.isSamePosition(this)) {
return null;
}
return new ItemBlockEntityElement(this, pos, previous.entityId1, previous.entityId2, false);
@@ -69,17 +69,10 @@ public class ItemBlockEntityElementConfig implements BlockEntityElementConfig<It
return this.lazyMetadataPacket.apply(player);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof ItemBlockEntityElementConfig that)) return false;
public boolean isSamePosition(ItemBlockEntityElementConfig that) {
return this.position.equals(that.position);
}
@Override
public int hashCode() {
return this.position.hashCode();
}
public static class Factory implements BlockEntityElementConfigFactory<ItemBlockEntityElement> {
@Override

View File

@@ -90,7 +90,7 @@ public class ItemDisplayBlockEntityElementConfig implements BlockEntityElementCo
if (this.blockLight != -1 && this.skyLight != -1) {
ItemDisplayEntityData.BrightnessOverride.addEntityData(this.blockLight << 4 | this.skyLight << 20, dataValues);
}
ItemDisplayEntityData.ViewRange.addEntityData(this.viewRange, dataValues);
ItemDisplayEntityData.ViewRange.addEntityData((float) (this.viewRange * player.displayEntityViewDistance()), dataValues);
return dataValues;
};
}
@@ -111,7 +111,7 @@ public class ItemDisplayBlockEntityElementConfig implements BlockEntityElementCo
@Override
public ItemDisplayBlockEntityElement createExact(World world, BlockPos pos, ItemDisplayBlockEntityElement previous) {
if (!previous.config.equals(this)) {
if (!previous.config.isSamePosition(this)) {
return null;
}
return new ItemDisplayBlockEntityElement(this, pos, previous.entityId, false);
@@ -170,9 +170,7 @@ public class ItemDisplayBlockEntityElementConfig implements BlockEntityElementCo
return this.lazyMetadataPacket.apply(player);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof ItemDisplayBlockEntityElementConfig that)) return false;
public boolean isSamePosition(ItemDisplayBlockEntityElementConfig that) {
return Float.compare(xRot, that.xRot) == 0 &&
Float.compare(yRot, that.yRot) == 0 &&
Objects.equal(position, that.position) &&
@@ -180,17 +178,6 @@ public class ItemDisplayBlockEntityElementConfig implements BlockEntityElementCo
Objects.equal(rotation, that.rotation);
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + Double.hashCode(xRot);
result = 31 * result + Double.hashCode(yRot);
result = 31 * result + (position != null ? position.hashCode() : 0);
result = 31 * result + (translation != null ? translation.hashCode() : 0);
result = 31 * result + (rotation != null ? rotation.hashCode() : 0);
return result;
}
public static class Factory implements BlockEntityElementConfigFactory<ItemDisplayBlockEntityElement> {
@Override

View File

@@ -76,7 +76,7 @@ public class TextDisplayBlockEntityElementConfig implements BlockEntityElementCo
if (this.blockLight != -1 && this.skyLight != -1) {
ItemDisplayEntityData.BrightnessOverride.addEntityData(this.blockLight << 4 | this.skyLight << 20, dataValues);
}
ItemDisplayEntityData.ViewRange.addEntityData(this.viewRange, dataValues);
ItemDisplayEntityData.ViewRange.addEntityData((float) (this.viewRange * player.displayEntityViewDistance()), dataValues);
return dataValues;
};
}
@@ -97,7 +97,7 @@ public class TextDisplayBlockEntityElementConfig implements BlockEntityElementCo
@Override
public TextDisplayBlockEntityElement createExact(World world, BlockPos pos, TextDisplayBlockEntityElement previous) {
if (!previous.config.equals(this)) {
if (!previous.config.isSamePosition(this)) {
return null;
}
return new TextDisplayBlockEntityElement(this, pos, previous.entityId, false);
@@ -144,9 +144,7 @@ public class TextDisplayBlockEntityElementConfig implements BlockEntityElementCo
return this.lazyMetadataPacket.apply(player);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof TextDisplayBlockEntityElementConfig that)) return false;
public boolean isSamePosition(TextDisplayBlockEntityElementConfig that) {
return Float.compare(xRot, that.xRot) == 0 &&
Float.compare(yRot, that.yRot) == 0 &&
Objects.equal(position, that.position) &&
@@ -154,17 +152,6 @@ public class TextDisplayBlockEntityElementConfig implements BlockEntityElementCo
Objects.equal(rotation, that.rotation);
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + Double.hashCode(xRot);
result = 31 * result + Double.hashCode(yRot);
result = 31 * result + (position != null ? position.hashCode() : 0);
result = 31 * result + (translation != null ? translation.hashCode() : 0);
result = 31 * result + (rotation != null ? rotation.hashCode() : 0);
return result;
}
public static class Factory implements BlockEntityElementConfigFactory<TextDisplayBlockEntityElement> {
@Override

View File

@@ -0,0 +1,10 @@
package net.momirealms.craftengine.bukkit.entity.data;
public class ArmorStandData<T> extends LivingEntityData<T> {
public static final ArmorStandData<Byte> ArmorStandFlags = new ArmorStandData<>(ArmorStandData.class, EntityDataValue.Serializers$BYTE, (byte) 0);
// rotations
public ArmorStandData(Class<?> clazz, Object serializer, T defaultValue) {
super(clazz, serializer, defaultValue);
}
}

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.plugin.reflection.minecraft.CoreReflections;
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.LegacyChatFormatter;
import net.momirealms.craftengine.core.world.Vec3d;
import net.momirealms.craftengine.core.world.WorldPosition;

View File

@@ -1,7 +1,6 @@
package net.momirealms.craftengine.bukkit.entity.furniture.element;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import net.momirealms.craftengine.bukkit.entity.data.BaseEntityData;
import net.momirealms.craftengine.bukkit.entity.data.ItemDisplayEntityData;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.core.entity.display.Billboard;
@@ -112,7 +111,7 @@ public class ItemDisplayFurnitureElementConfig implements FurnitureElementConfig
if (this.blockLight != -1 && this.skyLight != -1) {
ItemDisplayEntityData.BrightnessOverride.addEntityData(this.blockLight << 4 | this.skyLight << 20, dataValues);
}
ItemDisplayEntityData.ViewRange.addEntityData(this.viewRange, dataValues);
ItemDisplayEntityData.ViewRange.addEntityData((float) (this.viewRange * player.displayEntityViewDistance()), dataValues);
return dataValues;
};
}

View File

@@ -42,7 +42,8 @@ public class BukkitCommandManager extends AbstractCommandManager<CommandSender>
new SearchUsageAdminCommand(this, plugin),
new TestCommand(this, plugin),
new SetLocaleCommand(this, plugin),
new SetEntityViewDistanceScaleCommand(this, plugin),
new SetDisplayEntityViewDistanceScaleCommand(this, plugin),
new SetEntityCullingDistanceScaleCommand(this, plugin),
new ToggleEntityCullingCommand(this, plugin),
new UnsetLocaleCommand(this, plugin),
new DebugGetBlockStateRegistryIdCommand(this, plugin),

View File

@@ -1,14 +1,12 @@
package net.momirealms.craftengine.bukkit.plugin.command.feature;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
import net.momirealms.craftengine.core.plugin.command.FlagKeys;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.locale.MessageConstants;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -16,9 +14,9 @@ import org.incendo.cloud.Command;
import org.incendo.cloud.bukkit.parser.PlayerParser;
import org.incendo.cloud.parser.standard.DoubleParser;
public class SetEntityViewDistanceScaleCommand extends BukkitCommandFeature<CommandSender> {
public class SetDisplayEntityViewDistanceScaleCommand extends BukkitCommandFeature<CommandSender> {
public SetEntityViewDistanceScaleCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
public SetDisplayEntityViewDistanceScaleCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
super(commandManager, plugin);
}
@@ -29,24 +27,16 @@ public class SetEntityViewDistanceScaleCommand extends BukkitCommandFeature<Comm
.required("player", PlayerParser.playerParser())
.required("scale", DoubleParser.doubleParser(0.125, 8))
.handler(context -> {
if (!Config.enableEntityCulling()) {
plugin().senderFactory().wrap(context.sender()).sendMessage(Component.text("Entity culling is not enabled on this server").color(NamedTextColor.RED));
return;
}
if (Config.entityCullingViewDistance() <= 0) {
plugin().senderFactory().wrap(context.sender()).sendMessage(Component.text("View distance is not enabled on this server").color(NamedTextColor.RED));
return;
}
Player player = context.get("player");
double scale = context.get("scale");
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(player);
serverPlayer.setEntityCullingViewDistanceScale(scale);
handleFeedback(context, MessageConstants.COMMAND_ENTITY_VIEW_DISTANCE_SCALE_SET_SUCCESS, Component.text(scale), Component.text(player.getName()));
serverPlayer.setDisplayEntityViewDistanceScale(scale);
handleFeedback(context, MessageConstants.COMMAND_DISPLAY_ENTITY_VIEW_DISTANCE_SCALE_SET_SUCCESS, Component.text(scale), Component.text(player.getName()));
});
}
@Override
public String getFeatureID() {
return "set_entity_view_distance_scale";
return "set_display_entity_view_distance_scale";
}
}

View File

@@ -0,0 +1,42 @@
package net.momirealms.craftengine.bukkit.plugin.command.feature;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
import net.momirealms.craftengine.core.plugin.command.FlagKeys;
import net.momirealms.craftengine.core.plugin.locale.MessageConstants;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.incendo.cloud.Command;
import org.incendo.cloud.bukkit.parser.PlayerParser;
import org.incendo.cloud.parser.standard.DoubleParser;
public class SetEntityCullingDistanceScaleCommand extends BukkitCommandFeature<CommandSender> {
public SetEntityCullingDistanceScaleCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
super(commandManager, plugin);
}
@Override
public Command.Builder<? extends CommandSender> assembleCommand(org.incendo.cloud.CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
return builder
.flag(FlagKeys.SILENT_FLAG)
.required("player", PlayerParser.playerParser())
.required("scale", DoubleParser.doubleParser(0.125, 8))
.handler(context -> {
Player player = context.get("player");
double scale = context.get("scale");
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(player);
serverPlayer.setEntityCullingDistanceScale(scale);
handleFeedback(context, MessageConstants.COMMAND_ENTITY_CULLING_DISTANCE_SCALE_SET_SUCCESS, Component.text(scale), Component.text(player.getName()));
});
}
@Override
public String getFeatureID() {
return "set_entity_culling_distance_scale";
}
}

View File

@@ -5,16 +5,12 @@ import net.momirealms.craftengine.bukkit.entity.data.BaseEntityData;
import net.momirealms.craftengine.bukkit.entity.data.ItemEntityData;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
import net.momirealms.craftengine.bukkit.util.EntityDataUtils;
import net.momirealms.craftengine.bukkit.world.score.BukkitTeamManager;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.CustomItem;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.ItemSettings;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
import net.momirealms.craftengine.core.plugin.context.NetworkTextReplaceContext;

View File

@@ -79,7 +79,8 @@ import java.util.function.Predicate;
public class BukkitServerPlayer extends Player {
public static final Key SELECTED_LOCALE_KEY = Key.of("craftengine:locale");
public static final Key ENTITY_CULLING_VIEW_DISTANCE_SCALE = Key.of("craftengine:entity_culling_view_distance_scale");
public static final Key ENTITY_CULLING_DISTANCE_SCALE = Key.of("craftengine:entity_culling_distance_scale");
public static final Key DISPLAY_ENTITY_VIEW_DISTANCE_SCALE = Key.of("craftengine:display_entity_view_distance_scale");
public static final Key ENABLE_ENTITY_CULLING = Key.of("craftengine:enable_entity_culling");
public static final Key ENABLE_FURNITURE_DEBUG = Key.of("craftengine:enable_furniture_debug");
private final BukkitCraftEngine plugin;
@@ -165,6 +166,8 @@ public class BukkitServerPlayer extends Player {
private BukkitFurniture lastHitFurniture;
// 缓存的tick
private int lastHitFurnitureTick;
// 控制展示实体可见距离
private double displayEntityViewDistance;
public BukkitServerPlayer(BukkitCraftEngine plugin, @Nullable Channel channel) {
this.channel = channel;
@@ -190,7 +193,8 @@ public class BukkitServerPlayer extends Player {
this.isNameVerified = true;
byte[] bytes = player.getPersistentDataContainer().get(KeyUtils.toNamespacedKey(CooldownData.COOLDOWN_KEY), PersistentDataType.BYTE_ARRAY);
String locale = player.getPersistentDataContainer().get(KeyUtils.toNamespacedKey(SELECTED_LOCALE_KEY), PersistentDataType.STRING);
Double scale = player.getPersistentDataContainer().get(KeyUtils.toNamespacedKey(ENTITY_CULLING_VIEW_DISTANCE_SCALE), PersistentDataType.DOUBLE);
Double scale = player.getPersistentDataContainer().get(KeyUtils.toNamespacedKey(ENTITY_CULLING_DISTANCE_SCALE), PersistentDataType.DOUBLE);
this.displayEntityViewDistance = Optional.ofNullable(player.getPersistentDataContainer().get(KeyUtils.toNamespacedKey(DISPLAY_ENTITY_VIEW_DISTANCE_SCALE), PersistentDataType.DOUBLE)).orElse(1d);
this.enableEntityCulling = Optional.ofNullable(player.getPersistentDataContainer().get(KeyUtils.toNamespacedKey(ENABLE_ENTITY_CULLING), PersistentDataType.BOOLEAN)).orElse(true);
this.enableFurnitureDebug = Optional.ofNullable(player.getPersistentDataContainer().get(KeyUtils.toNamespacedKey(ENABLE_FURNITURE_DEBUG), PersistentDataType.BOOLEAN)).orElse(false);
this.culling.setDistanceScale(Optional.ofNullable(scale).orElse(1.0));
@@ -1400,10 +1404,22 @@ public class BukkitServerPlayer extends Player {
}
@Override
public void setEntityCullingViewDistanceScale(double value) {
public void setEntityCullingDistanceScale(double value) {
value = Math.min(Math.max(0.125, value), 8);
this.culling.setDistanceScale(value);
platformPlayer().getPersistentDataContainer().set(KeyUtils.toNamespacedKey(ENTITY_CULLING_VIEW_DISTANCE_SCALE), PersistentDataType.DOUBLE, value);
platformPlayer().getPersistentDataContainer().set(KeyUtils.toNamespacedKey(ENTITY_CULLING_DISTANCE_SCALE), PersistentDataType.DOUBLE, value);
}
@Override
public void setDisplayEntityViewDistanceScale(double value) {
value = Math.min(Math.max(0.125, value), 8);
this.displayEntityViewDistance = value;
platformPlayer().getPersistentDataContainer().set(KeyUtils.toNamespacedKey(DISPLAY_ENTITY_VIEW_DISTANCE_SCALE), PersistentDataType.DOUBLE, value);
}
@Override
public double displayEntityViewDistance() {
return this.displayEntityViewDistance;
}
@Override