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

修复map类型参数,增加debug功能

This commit is contained in:
XiaoMoMi
2025-06-18 17:57:54 +08:00
parent 89c35d2d41
commit 730ce99fe4
10 changed files with 31 additions and 76 deletions

View File

@@ -5,7 +5,6 @@ import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.command.feature.*;
import net.momirealms.craftengine.core.plugin.command.AbstractCommandManager;
import net.momirealms.craftengine.core.plugin.command.CommandFeature;
import net.momirealms.craftengine.core.plugin.command.parser.BlockStateParser;
import net.momirealms.craftengine.core.plugin.command.sender.Sender;
import org.bukkit.command.CommandSender;
import org.incendo.cloud.SenderMapper;
@@ -18,7 +17,7 @@ import java.util.List;
public class BukkitCommandManager extends AbstractCommandManager<CommandSender> {
private final BukkitCraftEngine plugin;
private final Index<String, CommandFeature<CommandSender>> INDEX;
private final Index<String, CommandFeature<CommandSender>> index;
public BukkitCommandManager(BukkitCraftEngine plugin) {
super(plugin, new LegacyPaperCommandManager<>(
@@ -27,7 +26,7 @@ public class BukkitCommandManager extends AbstractCommandManager<CommandSender>
SenderMapper.identity()
));
this.plugin = plugin;
this.INDEX = Index.create(CommandFeature::getFeatureID, List.of(
this.index = Index.create(CommandFeature::getFeatureID, List.of(
new ReloadCommand(this, plugin),
new GetItemCommand(this, plugin),
new GiveItemCommand(this, plugin),
@@ -59,7 +58,6 @@ public class BukkitCommandManager extends AbstractCommandManager<CommandSender>
));
final LegacyPaperCommandManager<CommandSender> manager = (LegacyPaperCommandManager<CommandSender>) getCommandManager();
manager.settings().set(ManagerSetting.ALLOW_UNSAFE_REGISTRATION, true);
manager.parserRegistry().registerParser(BlockStateParser.blockStateParser());
if (manager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
manager.registerBrigadier();
manager.brigadierManager().setNativeNumberSuggestions(true);
@@ -70,11 +68,11 @@ public class BukkitCommandManager extends AbstractCommandManager<CommandSender>
@Override
protected Sender wrapSender(CommandSender sender) {
return plugin.senderFactory().wrap(sender);
return this.plugin.senderFactory().wrap(sender);
}
@Override
public Index<String, CommandFeature<CommandSender>> features() {
return INDEX;
return this.index;
}
}

View File

@@ -293,7 +293,7 @@ items:
type: "minecraft:model"
path: "minecraft:item/custom/palm_trapdoor"
generation:
parent: "minecraft:block/custom/palm_trapdoor"
parent: "minecraft:block/custom/palm_trapdoor_bottom"
behavior:
type: block_item
block:
@@ -319,9 +319,21 @@ items:
template: "default:block_state/trapdoor"
arguments:
base_block: acacia_trapdoor
model_bottom_path: "minecraft:block/birch_trapdoor_bottom"
model_open_path: "minecraft:block/birch_trapdoor_open"
model_top_path: "minecraft:block/birch_trapdoor_top"
model_bottom_path: "minecraft:block/custom/palm_trapdoor_bottom"
model_bottom_generation:
parent: "minecraft:block/template_orientable_trapdoor_bottom"
textures:
texture: "minecraft:block/custom/palm_trapdoor"
model_open_path: "minecraft:block/custom/palm_trapdoor_open"
model_open_generation:
parent: "minecraft:block/template_orientable_trapdoor_open"
textures:
texture: "minecraft:block/custom/palm_trapdoor"
model_top_path: "minecraft:block/custom/palm_trapdoor_top"
model_top_generation:
parent: "minecraft:block/template_orientable_trapdoor_top"
textures:
texture: "minecraft:block/custom/palm_trapdoor"
recipes:
default:palm_planks:

View File

@@ -984,16 +984,19 @@ templates#block_states:
model:
path: ${model_bottom_path}
y: 90
generation: ${model_bottom_generation}
facing=east,half=bottom,open=true,waterlogged=false:
state: "${base_block}[facing=east,half=bottom,open=true,powered=true,waterlogged=false]"
model:
path: ${model_open_path}
y: 90
generation: ${model_open_generation}
facing=east,half=top,open=false,waterlogged=false:
state: "${base_block}[facing=east,half=top,open=false,powered=true,waterlogged=false]"
model:
path: ${model_top_path}
y: 90
generation: ${model_top_generation}
facing=east,half=top,open=true,waterlogged=false:
state: "${base_block}[facing=east,half=top,open=true,powered=true,waterlogged=false]"
model:

View File

@@ -424,6 +424,9 @@ public abstract class AbstractPackManager implements PackManager {
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/stripped_palm_log.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/stripped_palm_log_top.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/palm_leaves.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/palm_trapdoor.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/palm_door_top.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/palm_door_bottom.png");
// plants
plugin.saveResource("resources/default/configuration/plants.yml");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/fairy_flower_1.png");
@@ -529,6 +532,9 @@ public abstract class AbstractPackManager implements PackManager {
} else {
if (configEntry.getValue() instanceof Map<?, ?> configSection0) {
Map<String, Object> config = castToMap(configSection0, false);
if (Config.debug() && (boolean) config.getOrDefault("debug", false)) {
this.plugin.logger().info(GsonHelper.get().toJson(this.plugin.templateManager().applyTemplates(id, config)));
}
if ((boolean) config.getOrDefault("enable", true)) {
parser.parseSection(cached.pack(), cached.filePath(), id, MiscUtils.castToMap(this.plugin.templateManager().applyTemplates(id, config), false));
}

View File

@@ -1,64 +0,0 @@
package net.momirealms.craftengine.core.plugin.command.parser;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCaptionKeys;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.caption.CaptionVariable;
import org.incendo.cloud.component.CommandComponent;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.context.CommandInput;
import org.incendo.cloud.exception.parsing.ParserException;
import org.incendo.cloud.parser.ArgumentParseResult;
import org.incendo.cloud.parser.ArgumentParser;
import org.incendo.cloud.parser.ParserDescriptor;
import org.incendo.cloud.suggestion.BlockingSuggestionProvider;
import org.incendo.cloud.suggestion.Suggestion;
public class BlockStateParser<C> implements ArgumentParser<C, ImmutableBlockState>, BlockingSuggestionProvider.Strings<C> {
public static <C> @NonNull ParserDescriptor<C, ImmutableBlockState> blockStateParser() {
return ParserDescriptor.of(new BlockStateParser<>(), ImmutableBlockState.class);
}
public static <C> CommandComponent.@NonNull Builder<C, ImmutableBlockState> blockStateComponent() {
return CommandComponent.<C, ImmutableBlockState>builder().parser(blockStateParser());
}
@Override
public @NonNull ArgumentParseResult<@NonNull ImmutableBlockState> parse(@NonNull CommandContext<@NonNull C> commandContext, @NonNull CommandInput commandInput) {
String input = commandInput.readString();
ImmutableBlockState state = net.momirealms.craftengine.core.block.BlockStateParser.deserialize(input);
if (state == null) {
return ArgumentParseResult.failure(new BlockStateParseException(input, commandContext));
}
return ArgumentParseResult.success(state);
}
@Override
public @NonNull Iterable<@NonNull String> stringSuggestions(@NonNull CommandContext<C> commandContext, @NonNull CommandInput input) {
return CraftEngine.instance().blockManager().cachedSuggestions().stream().map(Suggestion::suggestion).toList();
}
public static final class BlockStateParseException extends ParserException {
private final String input;
public BlockStateParseException(
final @NonNull String input,
final @NonNull CommandContext<?> context
) {
super(
BlockStateParser.class,
context,
CraftEngineCaptionKeys.ARGUMENT_PARSE_FAILURE_BLOCK_STATE,
CaptionVariable.of("input", input)
);
this.input = input;
}
public @NonNull String input() {
return this.input;
}
}
}

View File

@@ -36,7 +36,7 @@ public class TemplateArguments {
public static TemplateArgument fromMap(Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
return MapTemplateArgument.FACTORY.create(map);
return new MapTemplateArgument(map);
} else {
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
TemplateArgumentFactory factory = BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY.getValue(key);

View File

@@ -71,7 +71,7 @@ public interface TemplateManager extends Manageable {
int separatorIndex = placeholderContent.indexOf(":-");
if (separatorIndex == -1) {
this.placeholder = placeholderContent;
this.defaultValue = this.rawText;
this.defaultValue = null;
} else {
this.placeholder = placeholderContent.substring(0, separatorIndex);
String defaultValueString = placeholderContent.substring(separatorIndex + 2);