mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
改进合并实现
This commit is contained in:
@@ -161,6 +161,7 @@ warning.config.recipe.smithing_transform.post_processor.missing_type: "<yellow>I
|
||||
warning.config.recipe.smithing_transform.post_processor.invalid_type: "<yellow>Issue found in file <arg:0> - The smithing transform recipe '<arg:1>' is using an invalid post processor type '<arg:2>'.</yellow>"
|
||||
warning.config.recipe.smithing_transform.post_processor.keep_component.missing_components: "<yellow>Issue found in file <arg:0> - The smithing transform recipe '<arg:1>' is missing the required argument 'components' for post-processors 'keep_components'.</yellow>"
|
||||
warning.config.recipe.smithing_transform.post_processor.keep_component.missing_tags: "<yellow>Issue found in file <arg:0> - The smithing transform recipe '<arg:1>' is missing the required argument 'tags' for post-processors 'keep_tags'.</yellow>"
|
||||
warning.config.recipe.smithing_transform.post_processor.keep_custom_data.missing_paths: "<yellow>Issue found in file <arg:0> - The smithing transform recipe '<arg:1>' is missing the required argument 'paths' for post-processors 'keep_custom_data'.</yellow>"
|
||||
warning.config.recipe.smithing_transform.missing_base: "<yellow>Issue found in file <arg:0> - The smithing transform recipe '<arg:1>' is missing the required 'base' argument.</yellow>"
|
||||
warning.config.recipe.smithing_trim.missing_base: "<yellow>Issue found in file <arg:0> - The smithing trim recipe '<arg:1>' is missing the required 'base' argument.</yellow>"
|
||||
warning.config.recipe.smithing_trim.missing_template_type: "<yellow>Issue found in file <arg:0> - The smithing trim recipe '<arg:1>' is missing the required 'template-type' argument.</yellow>"
|
||||
|
||||
@@ -159,6 +159,7 @@ warning.config.recipe.smithing_transform.post_processor.missing_type: "<yellow>
|
||||
warning.config.recipe.smithing_transform.post_processor.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 锻造升级配方 '<arg:1>' 使用了无效的后处理器类型 '<arg:2>'</yellow>"
|
||||
warning.config.recipe.smithing_transform.post_processor.keep_component.missing_components: "<yellow>在文件 <arg:0> 发现问题 - 锻造升级配方 '<arg:1>' 的 'keep_components' 后处理器缺少必需的 'components' 参数</yellow>"
|
||||
warning.config.recipe.smithing_transform.post_processor.keep_component.missing_tags: "<yellow>在文件 <arg:0> 发现问题 - 锻造升级配方 '<arg:1>' 的 'keep_tags' 后处理器缺少必需的 'tags' 参数</yellow>"
|
||||
warning.config.recipe.smithing_transform.post_processor.keep_custom_data.missing_paths: "<yellow>在文件 <arg:0> 发现问题 - 锻造升级配方 '<arg:1>' 的 'keep_custom_data' 后处理器缺少必需的 'paths' 参数</yellow>"
|
||||
warning.config.recipe.smithing_transform.missing_base: "<yellow>在文件 <arg:0> 发现问题 - 锻造升级配方 '<arg:1>' 缺少必需的 'base' 参数</yellow>"
|
||||
warning.config.recipe.smithing_trim.missing_base: "<yellow>在文件 <arg:0> 发现问题 - 锻造纹饰配方 '<arg:1>' 缺少必需的 'base' 参数</yellow>"
|
||||
warning.config.recipe.smithing_trim.missing_template_type: "<yellow>在文件 <arg:0> 发现问题 - 锻造纹饰配方 '<arg:1>' 缺少必需的 'template-type' 参数</yellow>"
|
||||
|
||||
@@ -155,7 +155,6 @@ public class CustomSmithingTransformRecipe<T> extends AbstractedFixedResultRecip
|
||||
private T createSmithingResult(Item<T> base, T result) {
|
||||
Item<T> wrappedResult = (Item<T>) CraftEngine.instance().itemManager().wrap(result);
|
||||
Item<T> finalResult = wrappedResult;
|
||||
Optional<Key> customId = finalResult.customId(); // 修复在保留custom_data组件的时候意外保留前物品的id
|
||||
if (this.mergeComponents) {
|
||||
finalResult = base.mergeCopy(wrappedResult);
|
||||
}
|
||||
@@ -164,9 +163,6 @@ public class CustomSmithingTransformRecipe<T> extends AbstractedFixedResultRecip
|
||||
processor.accept(base, wrappedResult, finalResult);
|
||||
}
|
||||
}
|
||||
if (customId.isPresent()) {
|
||||
finalResult.customId(customId.get());
|
||||
}
|
||||
return finalResult.getItem();
|
||||
}
|
||||
|
||||
@@ -233,10 +229,12 @@ public class CustomSmithingTransformRecipe<T> extends AbstractedFixedResultRecip
|
||||
public static final Key KEEP_COMPONENTS = Key.of("craftengine:keep_components");
|
||||
public static final Key KEEP_TAGS = Key.of("craftengine:keep_tags");
|
||||
public static final Key MERGE_ENCHANTMENTS = Key.of("craftengine:merge_enchantments");
|
||||
public static final Key KEEP_CUSTOM_DATA = Key.of("craftengine:keep_custom_data");
|
||||
|
||||
static {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
register(KEEP_COMPONENTS, KeepComponents.FACTORY);
|
||||
register(KEEP_CUSTOM_DATA, KeepCustomData.FACTORY);
|
||||
} else {
|
||||
register(KEEP_TAGS, KeepTags.FACTORY);
|
||||
}
|
||||
@@ -316,6 +314,42 @@ public class CustomSmithingTransformRecipe<T> extends AbstractedFixedResultRecip
|
||||
}
|
||||
}
|
||||
|
||||
public static class KeepCustomData implements ItemDataProcessor {
|
||||
public static final Factory FACTORY = new Factory();
|
||||
private final List<String[]> paths;
|
||||
|
||||
public KeepCustomData(List<String[]> data) {
|
||||
this.paths = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Item<?> item1, Item<?> item2, Item<?> item3) {
|
||||
for (String[] path : this.paths) {
|
||||
Object dataObj = item1.getJavaTag((Object[]) path);
|
||||
if (dataObj != null) {
|
||||
item3.setTag(dataObj, (Object[]) path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return ItemDataProcessors.KEEP_CUSTOM_DATA;
|
||||
}
|
||||
|
||||
public static class Factory implements ProcessorFactory {
|
||||
|
||||
@Override
|
||||
public ItemDataProcessor create(Map<String, Object> arguments) {
|
||||
List<String> paths = MiscUtils.getAsStringList(ResourceConfigUtils.requireNonNullOrThrow(
|
||||
arguments.get("paths"),
|
||||
"warning.config.recipe.smithing_transform.post_processor.keep_custom_data.missing_paths")
|
||||
);
|
||||
return new KeepCustomData(paths.stream().map(it -> it.split("\\.")).toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class KeepComponents implements ItemDataProcessor {
|
||||
public static final Factory FACTORY = new Factory();
|
||||
private final List<Key> components;
|
||||
@@ -340,6 +374,7 @@ public class CustomSmithingTransformRecipe<T> extends AbstractedFixedResultRecip
|
||||
}
|
||||
|
||||
public static class Factory implements ProcessorFactory {
|
||||
private static final Key CUSTOM_DATA = Key.of("minecraft", "custom_data");
|
||||
|
||||
@Override
|
||||
public ItemDataProcessor create(Map<String, Object> arguments) {
|
||||
@@ -348,7 +383,7 @@ public class CustomSmithingTransformRecipe<T> extends AbstractedFixedResultRecip
|
||||
throw new LocalizedResourceConfigException("warning.config.recipe.smithing_transform.post_processor.keep_component.missing_components");
|
||||
}
|
||||
List<String> components = MiscUtils.getAsStringList(componentsObj);
|
||||
return new KeepComponents(components.stream().map(Key::of).toList());
|
||||
return new KeepComponents(components.stream().map(Key::of).filter(it -> !CUSTOM_DATA.equals(it)).toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user