mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
添加实体显示距离、盔甲架元素
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -129,11 +129,17 @@ unset_locale:
|
||||
usage:
|
||||
- /ce feature locale unset
|
||||
|
||||
set_entity_view_distance_scale:
|
||||
set_display_entity_view_distance_scale:
|
||||
enable: true
|
||||
permission: ce.command.admin.set_entity_view_distance_scale
|
||||
permission: ce.command.admin.set_display_entity_view_distance_scale
|
||||
usage:
|
||||
- /ce feature entity-view-distance-scale set
|
||||
- /ce feature display-entity-view-distance-scale set
|
||||
|
||||
set_entity_culling_distance_scale:
|
||||
enable: true
|
||||
permission: ce.command.admin.set_entity_culling_distance_scale
|
||||
usage:
|
||||
- /ce feature entity-culling-distance-scale set
|
||||
|
||||
toggle_entity_culling:
|
||||
enable: true
|
||||
|
||||
@@ -576,11 +576,6 @@ client-optimization:
|
||||
bucket-size: 1000
|
||||
restore-per-tick: 25
|
||||
|
||||
# [Premium Exclusive]
|
||||
bedrock-edition-support:
|
||||
enable: false
|
||||
player-prefix: "!"
|
||||
|
||||
# Enables or disables debug mode
|
||||
debug:
|
||||
common: false
|
||||
|
||||
@@ -88,7 +88,8 @@ command.send_resource_pack.success.multiple: "<white>Send resource packs to <arg
|
||||
command.locale.set.failure: "<red>Invalid locale format: <arg:0></red>"
|
||||
command.locale.set.success: "<white>Selected locale has been set to <arg:0> for <arg:1></white>"
|
||||
command.locale.unset.success: "<white>Cleared selected locale for <arg:0></white>"
|
||||
command.entity_view_distance_scale.set.success: "<white>Entity view distance scale updated to <arg:0> for <arg:1></white>"
|
||||
command.display_entity_view_distance_scale.set.success: "<white>Display entity view distance scale updated to <arg:0> for <arg:1></white>"
|
||||
command.entity_culling_distance_scale.set.success: "<white>Entity culling distance scale updated to <arg:0> for <arg:1></white>"
|
||||
command.entity_culling.toggle.success: "<white>Entity culling status updated to <arg:0> for <arg:1></white>"
|
||||
warning.network.resource_pack.unverified_uuid: "<yellow>Player <arg:0> is attempting to request a resource pack using a UUID (<arg:1>) that is not authenticated by the server.</yellow>"
|
||||
warning.config.pack.duplicated_files: "<red>Duplicated files Found. Please resolve them through config.yml 'resource-pack.duplicated-files-handler' section.</red>"
|
||||
|
||||
@@ -88,7 +88,8 @@ command.send_resource_pack.success.multiple: "<white>发送资源包给 <arg:0>
|
||||
command.locale.set.failure: "<red>区域设置格式无效: <arg:0></red>"
|
||||
command.locale.set.success: "<white>已为 <arg:1> 更新选定区域设置为 <arg:0></white>"
|
||||
command.locale.unset.success: "<white>已清除 <arg:0> 的选定区域设置</white>"
|
||||
command.entity_view_distance_scale.set.success: "<white>已为 <arg:1> 的实体可见距离百分比设置为 <arg:0></white>"
|
||||
command.display_entity_view_distance_scale.set.success: "<white>已为 <arg:1> 的展示实体可见距离百分比设置为 <arg:0></white>"
|
||||
command.entity_culling_distance_scale.set.success: "<white>已为 <arg:1> 的实体剔除距离百分比设置为 <arg:0></white>"
|
||||
command.entity_culling.toggle.success: "<white>已为 <arg:1> 的实体剔除状态设置为 <arg:0></white>"
|
||||
warning.network.resource_pack.unverified_uuid: "<yellow>玩家 <arg:0> 使用未经服务器验证的 UUID (<arg:1>) 尝试请求获取资源包</yellow>"
|
||||
warning.config.pack.duplicated_files: "<red>发现重复文件 请通过 config.yml 的 'resource-pack.duplicated-files-handler' 部分解决</red>"
|
||||
|
||||
@@ -14,6 +14,7 @@ public abstract class BlockEntityElementConfigs {
|
||||
public static final Key ITEM_DISPLAY = Key.of("craftengine:item_display");
|
||||
public static final Key TEXT_DISPLAY = Key.of("craftengine:text_display");
|
||||
public static final Key ITEM = Key.of("craftengine:item");
|
||||
public static final Key ARMOR_STAND = Key.of("craftengine:armor_stand");
|
||||
|
||||
public static void register(Key key, BlockEntityElementConfigFactory<?> type) {
|
||||
((WritableRegistry<BlockEntityElementConfigFactory<?>>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE)
|
||||
|
||||
@@ -192,7 +192,11 @@ public abstract class Player extends AbstractEntity implements NetWorkUser {
|
||||
|
||||
public abstract void setSelectedLocale(@Nullable Locale locale);
|
||||
|
||||
public abstract void setEntityCullingViewDistanceScale(double value);
|
||||
public abstract void setEntityCullingDistanceScale(double value);
|
||||
|
||||
public abstract void setDisplayEntityViewDistanceScale(double value);
|
||||
|
||||
public abstract double displayEntityViewDistance();
|
||||
|
||||
public abstract void setEnableEntityCulling(boolean enable);
|
||||
|
||||
|
||||
@@ -1222,6 +1222,14 @@ public class Config {
|
||||
return instance.client_optimization$entity_culling$ray_tracing;
|
||||
}
|
||||
|
||||
public static boolean enableBedrockEditionSupport() {
|
||||
return instance.bedrock_edition_support$enable;
|
||||
}
|
||||
|
||||
public static String bedrockEditionPlayerPrefix() {
|
||||
return instance.bedrock_edition_support$player_prefix;
|
||||
}
|
||||
|
||||
public YamlDocument loadOrCreateYamlData(String fileName) {
|
||||
Path path = this.plugin.dataFolderPath().resolve(fileName);
|
||||
if (!Files.exists(path)) {
|
||||
|
||||
@@ -41,6 +41,7 @@ public interface MessageConstants {
|
||||
TranslatableComponent.Builder COMMAND_ITEM_CLEAR_FAILED_MULTIPLE = Component.translatable().key("command.item.clear.failed.multiple");
|
||||
TranslatableComponent.Builder COMMAND_ITEM_CLEAR_TEST_SINGLE = Component.translatable().key("command.item.clear.test.single");
|
||||
TranslatableComponent.Builder COMMAND_ITEM_CLEAR_TEST_MULTIPLE = Component.translatable().key("command.item.clear.test.multiple");
|
||||
TranslatableComponent.Builder COMMAND_ENTITY_VIEW_DISTANCE_SCALE_SET_SUCCESS = Component.translatable().key("command.entity_view_distance_scale.set.success");
|
||||
TranslatableComponent.Builder COMMAND_DISPLAY_ENTITY_VIEW_DISTANCE_SCALE_SET_SUCCESS = Component.translatable().key("command.display_entity_view_distance_scale.set.success");
|
||||
TranslatableComponent.Builder COMMAND_ENTITY_CULLING_DISTANCE_SCALE_SET_SUCCESS = Component.translatable().key("command.entity_culling_distance_scale.set.success");
|
||||
TranslatableComponent.Builder COMMAND_TOGGLE_ENTITY_CULLING_SUCCESS = Component.translatable().key("command.entity_culling.toggle.success");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Project settings
|
||||
project_version=0.0.65.19
|
||||
project_version=0.0.66
|
||||
config_version=60
|
||||
lang_version=43
|
||||
project_group=net.momirealms
|
||||
@@ -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.145
|
||||
nms_helper_version=1.0.146
|
||||
evalex_version=3.5.0
|
||||
reactive_streams_version=1.0.4
|
||||
amazon_awssdk_version=2.38.7
|
||||
@@ -59,9 +59,9 @@ concurrent_util_version=0.0.3
|
||||
bucket4j_version=8.15.0
|
||||
|
||||
# Proxy settings
|
||||
#systemProp.socks.proxyHost=127.0.0.1
|
||||
#systemProp.socks.proxyPort=7890
|
||||
#systemProp.http.proxyHost=127.0.0.1
|
||||
#systemProp.http.proxyPort=7890
|
||||
#systemProp.https.proxyHost=127.0.0.1
|
||||
#systemProp.https.proxyPort=7890
|
||||
systemProp.socks.proxyHost=127.0.0.1
|
||||
systemProp.socks.proxyPort=7890
|
||||
systemProp.http.proxyHost=127.0.0.1
|
||||
systemProp.http.proxyPort=7890
|
||||
systemProp.https.proxyHost=127.0.0.1
|
||||
systemProp.https.proxyPort=7890
|
||||
Reference in New Issue
Block a user