diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/item/MMOItemsSource.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/item/MMOItemsSource.java index 9cfc2ce73..68f5831af 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/item/MMOItemsSource.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/item/MMOItemsSource.java @@ -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 { diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/BukkitAdaptors.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/BukkitAdaptors.java index c667f832e..092a25cad 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/BukkitAdaptors.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/BukkitAdaptors.java @@ -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 adapt(@NotNull final ItemStack item) { + return BukkitItemManager.instance().wrap(item); + } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElement.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElement.java new file mode 100644 index 000000000..dee58c501 --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElement.java @@ -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); + } + } +} diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElementConfig.java new file mode 100644 index 000000000..6953c474f --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ArmorStandBlockEntityElementConfig.java @@ -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 { + public static final Factory FACTORY = new Factory(); + private final Function> lazyMetadataPacket; + private final Function> item; + private final Vector3f scale; + private final Vector3f position; + private final float xRot; + private final float yRot; + private final boolean small; + + public ArmorStandBlockEntityElementConfig(Function> 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 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 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 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 { + + @Override + public ArmorStandBlockEntityElementConfig create(Map 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") + ); + } + } +} diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/BukkitBlockEntityElementConfigs.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/BukkitBlockEntityElementConfigs.java index ee182e392..7d7ad348a 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/BukkitBlockEntityElementConfigs.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/BukkitBlockEntityElementConfigs.java @@ -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() {} diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemBlockEntityElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemBlockEntityElementConfig.java index 51c9c661e..de5f09f40 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemBlockEntityElementConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemBlockEntityElementConfig.java @@ -46,7 +46,7 @@ public class ItemBlockEntityElementConfig implements BlockEntityElementConfig { @Override diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemDisplayBlockEntityElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemDisplayBlockEntityElementConfig.java index 296b59051..6b4c3e2e6 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemDisplayBlockEntityElementConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/ItemDisplayBlockEntityElementConfig.java @@ -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 { @Override diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/TextDisplayBlockEntityElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/TextDisplayBlockEntityElementConfig.java index 3709a8d71..dc6fa84d9 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/TextDisplayBlockEntityElementConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/TextDisplayBlockEntityElementConfig.java @@ -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 { @Override diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/data/ArmorStandData.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/data/ArmorStandData.java new file mode 100644 index 000000000..b57c49046 --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/data/ArmorStandData.java @@ -0,0 +1,10 @@ +package net.momirealms.craftengine.bukkit.entity.data; + +public class ArmorStandData extends LivingEntityData { + public static final ArmorStandData ArmorStandFlags = new ArmorStandData<>(ArmorStandData.class, EntityDataValue.Serializers$BYTE, (byte) 0); + // rotations + + public ArmorStandData(Class clazz, Object serializer, T defaultValue) { + super(clazz, serializer, defaultValue); + } +} \ No newline at end of file diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ItemDisplayFurnitureElement.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ItemDisplayFurnitureElement.java index b63daf007..8557e6493 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ItemDisplayFurnitureElement.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ItemDisplayFurnitureElement.java @@ -4,12 +4,10 @@ import it.unimi.dsi.fastutil.ints.IntArrayList; import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections; import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.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; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ItemDisplayFurnitureElementConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ItemDisplayFurnitureElementConfig.java index 7b94bcd76..d5658154c 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ItemDisplayFurnitureElementConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/element/ItemDisplayFurnitureElementConfig.java @@ -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; }; } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java index 533032261..5f44c5689 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/BukkitCommandManager.java @@ -42,7 +42,8 @@ public class BukkitCommandManager extends AbstractCommandManager 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), diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SetEntityViewDistanceScaleCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SetDisplayEntityViewDistanceScaleCommand.java similarity index 59% rename from bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SetEntityViewDistanceScaleCommand.java rename to bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SetDisplayEntityViewDistanceScaleCommand.java index d8a9d0d9a..e10907455 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SetEntityViewDistanceScaleCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SetDisplayEntityViewDistanceScaleCommand.java @@ -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 { +public class SetDisplayEntityViewDistanceScaleCommand extends BukkitCommandFeature { - public SetEntityViewDistanceScaleCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + public SetDisplayEntityViewDistanceScaleCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { super(commandManager, plugin); } @@ -29,24 +27,16 @@ public class SetEntityViewDistanceScaleCommand extends BukkitCommandFeature { - 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"; } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SetEntityCullingDistanceScaleCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SetEntityCullingDistanceScaleCommand.java new file mode 100644 index 000000000..89968985e --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/SetEntityCullingDistanceScaleCommand.java @@ -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 { + + public SetEntityCullingDistanceScaleCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + super(commandManager, plugin); + } + + @Override + public Command.Builder assembleCommand(org.incendo.cloud.CommandManager manager, Command.Builder 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"; + } +} diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/handler/ItemPacketHandler.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/handler/ItemPacketHandler.java index 6f01fdc82..78e62a2d1 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/handler/ItemPacketHandler.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/handler/ItemPacketHandler.java @@ -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; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java index af3c1a1a1..b29efe890 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java @@ -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 diff --git a/common-files/src/main/resources/commands.yml b/common-files/src/main/resources/commands.yml index 24e0bcccf..e9929cd06 100644 --- a/common-files/src/main/resources/commands.yml +++ b/common-files/src/main/resources/commands.yml @@ -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 diff --git a/common-files/src/main/resources/config.yml b/common-files/src/main/resources/config.yml index 8252c48c1..26716aa71 100644 --- a/common-files/src/main/resources/config.yml +++ b/common-files/src/main/resources/config.yml @@ -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 diff --git a/common-files/src/main/resources/translations/en.yml b/common-files/src/main/resources/translations/en.yml index e42ae799d..1a1ebdd0c 100644 --- a/common-files/src/main/resources/translations/en.yml +++ b/common-files/src/main/resources/translations/en.yml @@ -88,7 +88,8 @@ command.send_resource_pack.success.multiple: "Send resource packs to Invalid locale format: " command.locale.set.success: "Selected locale has been set to for " command.locale.unset.success: "Cleared selected locale for " -command.entity_view_distance_scale.set.success: "Entity view distance scale updated to for " +command.display_entity_view_distance_scale.set.success: "Display entity view distance scale updated to for " +command.entity_culling_distance_scale.set.success: "Entity culling distance scale updated to for " command.entity_culling.toggle.success: "Entity culling status updated to for " warning.network.resource_pack.unverified_uuid: "Player is attempting to request a resource pack using a UUID () that is not authenticated by the server." warning.config.pack.duplicated_files: "Duplicated files Found. Please resolve them through config.yml 'resource-pack.duplicated-files-handler' section." diff --git a/common-files/src/main/resources/translations/zh_cn.yml b/common-files/src/main/resources/translations/zh_cn.yml index e1f1bebad..4219c13b6 100644 --- a/common-files/src/main/resources/translations/zh_cn.yml +++ b/common-files/src/main/resources/translations/zh_cn.yml @@ -88,7 +88,8 @@ command.send_resource_pack.success.multiple: "发送资源包给 command.locale.set.failure: "区域设置格式无效: " command.locale.set.success: "已为 更新选定区域设置为 " command.locale.unset.success: "已清除 的选定区域设置" -command.entity_view_distance_scale.set.success: "已为 的实体可见距离百分比设置为 " +command.display_entity_view_distance_scale.set.success: "已为 的展示实体可见距离百分比设置为 " +command.entity_culling_distance_scale.set.success: "已为 的实体剔除距离百分比设置为 " command.entity_culling.toggle.success: "已为 的实体剔除状态设置为 " warning.network.resource_pack.unverified_uuid: "玩家 使用未经服务器验证的 UUID () 尝试请求获取资源包" warning.config.pack.duplicated_files: "发现重复文件 请通过 config.yml 的 'resource-pack.duplicated-files-handler' 部分解决" diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigs.java b/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigs.java index c355c4eb2..a267612c9 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigs.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigs.java @@ -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>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE) diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java b/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java index b8792bde0..f7f85bdf5 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java @@ -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); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java index c38549237..f343ce3f3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java @@ -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)) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MessageConstants.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MessageConstants.java index f8cfbd946..fafd81f68 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MessageConstants.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MessageConstants.java @@ -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"); } diff --git a/gradle.properties b/gradle.properties index 29c7148dc..2a2f5f0f6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file +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 \ No newline at end of file