From 22d41bf78815e406edaef9119f9cea978dd7792f Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Tue, 6 May 2025 17:10:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0debug=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worldedit/FastAsyncWorldEditDelegate.java | 2 +- bukkit/loader/src/main/resources/commands.yml | 7 +++ .../src/main/resources/translations/en.yml | 2 + .../plugin/command/BukkitCommandManager.java | 1 + .../DebugIsSectionInjectedCommand.java | 50 +++++++++++++++++++ .../plugin/command/feature/ReloadCommand.java | 1 - .../plugin/injector/BukkitInjector.java | 9 +++- .../plugin/event/BlockEventConditions.java | 6 +-- gradle.properties | 2 +- .../craftengine/mod/CraftEnginePlugin.java | 1 + 10 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/DebugIsSectionInjectedCommand.java diff --git a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java index 79a7d027a..7f82fe30b 100644 --- a/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java +++ b/bukkit/compatibility/src/main/java/net/momirealms/craftengine/bukkit/compatibility/worldedit/FastAsyncWorldEditDelegate.java @@ -64,7 +64,7 @@ public class FastAsyncWorldEditDelegate extends AbstractDelegateExtent { @Subscribe @SuppressWarnings("unused") public void onEditSessionEvent(EditSessionEvent event) { - if (event.getStage() == EditSession.Stage.BEFORE_HISTORY || event.getStage() == EditSession.Stage.BEFORE_CHANGE) { + if (event.getStage() == EditSession.Stage.BEFORE_CHANGE) { event.setExtent(new FastAsyncWorldEditDelegate(event)); } } diff --git a/bukkit/loader/src/main/resources/commands.yml b/bukkit/loader/src/main/resources/commands.yml index be61cd3c6..fdf4e1613 100644 --- a/bukkit/loader/src/main/resources/commands.yml +++ b/bukkit/loader/src/main/resources/commands.yml @@ -168,6 +168,13 @@ debug_target_block: - /craftengine debug target-block - /ce debug target-block +debug_is_section_injected: + enable: true + permission: ce.command.debug.is_section_injected + usage: + - /craftengine debug is-section-injected + - /ce debug is-section-injected + debug_test: enable: true permission: ce.command.debug.test diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index 96cd97723..2d63d9711 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -222,6 +222,8 @@ warning.config.block.behavior.leaves.missing_distance: "Issue found in f warning.config.block.behavior.sapling.missing_stage: "Issue found in file - The block '' is missing the required 'stage' property for 'sapling_block' behavior." warning.config.block.behavior.sapling.missing_feature: "Issue found in file - The block '' is missing the required 'feature' argument for 'sapling_block' behavior." warning.config.block.behavior.strippable.missing_stripped: "Issue found in file - The block '' is missing the required 'stripped' argument for 'strippable_block' behavior." +warning.config.block.event.condition.missing_type: "Issue found in file - The block '' is missing the required 'type' argument for event condition." +warning.config.block.event.condition.invalid_type: "Issue found in file - The block '' is using an invalid 'type' argument for event condition." warning.config.model.generation.missing_parent: "Issue found in file - The config '' is missing the required 'parent' argument in 'generation' section." warning.config.model.generation.conflict: "Issue found in file - Failed to generate model for '' as two or more configurations attempt to generate different json models with the same path: ''." warning.config.model.generation.texture.invalid: "Issue found in file - The config '' has a texture '' with path '' that contains illegal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters." 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 0b5d4030e..c1f1c3f39 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 @@ -46,6 +46,7 @@ public class BukkitCommandManager extends AbstractCommandManager new DebugSetBlockCommand(this, plugin), new DebugSpawnFurnitureCommand(this, plugin), new DebugTargetBlockCommand(this, plugin), + new DebugIsSectionInjectedCommand(this, plugin), new TotemAnimationCommand(this, plugin), new EnableResourceCommand(this, plugin), new DisableResourceCommand(this, plugin), diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/DebugIsSectionInjectedCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/DebugIsSectionInjectedCommand.java new file mode 100644 index 000000000..b14e164e9 --- /dev/null +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/DebugIsSectionInjectedCommand.java @@ -0,0 +1,50 @@ +package net.momirealms.craftengine.bukkit.plugin.command.feature; + +import net.kyori.adventure.text.Component; +import net.momirealms.craftengine.bukkit.nms.FastNMS; +import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; +import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector; +import net.momirealms.craftengine.core.plugin.CraftEngine; +import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; +import net.momirealms.craftengine.core.plugin.command.sender.Sender; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext; +import net.momirealms.craftengine.core.util.AdventureHelper; +import net.momirealms.craftengine.core.world.chunk.CESection; +import org.bukkit.Chunk; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.incendo.cloud.Command; +import org.incendo.cloud.parser.standard.StringParser; + +public class DebugIsSectionInjectedCommand extends BukkitCommandFeature { + + public DebugIsSectionInjectedCommand(CraftEngineCommandManager commandManager, CraftEngine plugin) { + super(commandManager, plugin); + } + + @Override + public Command.Builder assembleCommand(org.incendo.cloud.CommandManager manager, Command.Builder builder) { + return builder + .senderType(Player.class) + .handler(context -> { + Player player = context.sender(); + Chunk chunk = player.getChunk(); + Object worldServer = FastNMS.INSTANCE.field$CraftChunk$worldServer(chunk); + Object chunkSource = FastNMS.INSTANCE.method$ServerLevel$getChunkSource(worldServer); + Object levelChunk = FastNMS.INSTANCE.method$ServerChunkCache$getChunkAtIfLoadedMainThread(chunkSource, chunk.getX(), chunk.getZ()); + Object[] sections = FastNMS.INSTANCE.method$ChunkAccess$getSections(levelChunk); + int i = 0; + Sender sender = plugin().senderFactory().wrap(player); + for (Object section : sections) { + sender.sendMessage(Component.text("Section #" + i + ": " + BukkitInjector.isSectionInjected(section))); + i++; + } + }); + } + + @Override + public String getFeatureID() { + return "debug_is_section_injected"; + } +} diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java index b1ee0e30d..db8d277a1 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/ReloadCommand.java @@ -4,7 +4,6 @@ import net.kyori.adventure.text.Component; import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; -import net.momirealms.craftengine.core.plugin.locale.LocalizedException; import net.momirealms.craftengine.core.plugin.locale.MessageConstants; import org.bukkit.command.CommandSender; import org.incendo.cloud.Command; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/injector/BukkitInjector.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/injector/BukkitInjector.java index b68ef4a2d..79ddd56c3 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/injector/BukkitInjector.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/injector/BukkitInjector.java @@ -391,7 +391,7 @@ public class BukkitInjector { public synchronized static void injectLevelChunkSection(Object targetSection, CESection ceSection, CEWorld ceWorld, CEChunk chunk, SectionPos pos) { try { Object container = FastNMS.INSTANCE.field$LevelChunkSection$states(targetSection); - if (!clazz$InjectedPalettedContainer.isInstance(container)) { + if (!(container instanceof InjectedPalettedContainerHolder)) { InjectedPalettedContainerHolder injectedObject; if (Config.fastPaletteInjection()) { injectedObject = FastNMS.INSTANCE.createInjectedPalettedContainerHolder(container); @@ -411,6 +411,11 @@ public class BukkitInjector { } } + public static boolean isSectionInjected(Object section) { + Object container = FastNMS.INSTANCE.field$LevelChunkSection$states(section); + return container instanceof InjectedPalettedContainerHolder; + } + public synchronized static void uninjectLevelChunkSection(Object section) { try { Object states = FastNMS.INSTANCE.field$LevelChunkSection$states(section); @@ -707,6 +712,8 @@ public class BukkitInjector { ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockStateUnsafe(stateId); ImmutableBlockState previousImmutableBlockState = section.setBlockState(x, y, z, immutableBlockState); // 如果之前的自定义块(空气)和当前自定义块不同 + System.out.println("1:" + immutableBlockState); + System.out.println("2:" + previousImmutableBlockState); if (previousImmutableBlockState != immutableBlockState) { holder.ceChunk().setDirty(true); if (Config.enableLightSystem() && !immutableBlockState.isEmpty()) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/event/BlockEventConditions.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/event/BlockEventConditions.java index b6883e577..5cb58ed8a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/event/BlockEventConditions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/event/BlockEventConditions.java @@ -14,18 +14,18 @@ import java.util.Map; public class BlockEventConditions { public static Condition fromMap(Map map) { - String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "TODO I18N"); + String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.block.event.condition.missing_type"); Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); if (key.value().charAt(0) == '!') { Factory> factory = BuiltInRegistries.PLAYER_BLOCK_CONDITION_FACTORY.getValue(new Key(key.namespace(), key.value().substring(1))); if (factory == null) { - throw new LocalizedResourceConfigException("TODO I18N", type); + throw new LocalizedResourceConfigException("warning.config.block.event.condition.invalid_type", type); } return new InvertedCondition<>(factory.create(map)); } else { Factory> factory = BuiltInRegistries.PLAYER_BLOCK_CONDITION_FACTORY.getValue(key); if (factory == null) { - throw new LocalizedResourceConfigException("TODO I18N", type); + throw new LocalizedResourceConfigException("warning.config.block.event.condition.invalid_type", type); } return factory.create(map); } diff --git a/gradle.properties b/gradle.properties index 4c60323b6..749c4cce7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=0.0.53-beta.3 +project_version=0.0.53-beta.4 config_version=31 lang_version=12 project_group=net.momirealms diff --git a/server-mod/v1_21_5/src/main/java/net/momirealms/craftengine/mod/CraftEnginePlugin.java b/server-mod/v1_21_5/src/main/java/net/momirealms/craftengine/mod/CraftEnginePlugin.java index 6cb356a90..c0b7d7bf1 100644 --- a/server-mod/v1_21_5/src/main/java/net/momirealms/craftengine/mod/CraftEnginePlugin.java +++ b/server-mod/v1_21_5/src/main/java/net/momirealms/craftengine/mod/CraftEnginePlugin.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.mod; +import net.minecraft.world.level.chunk.LevelChunkSection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.objectweb.asm.tree.ClassNode;