Skip to content

Commit

Permalink
[1.6.0-dev9]添加创建铁砧配方的GUI,兼容1.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Dec 7, 2023
1 parent 3de4455 commit cc0d42f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.6.0-dev8"
version = "1.6.0-dev9"

plugins {
`java-library`
Expand Down Expand Up @@ -41,7 +41,7 @@ dependencies {
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.5.0b")
compileOnly("com.github.oraxen:oraxen:1.160.0")
compileOnly("io.lumine:Mythic-Dist:5.3.5")
implementation("com.crypticlib:CrypticLib:0.5.8")
implementation("com.crypticlib:CrypticLib:0.5.9")
}

group = "com.github.yufiriamazenta"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.yufiriamazenta.craftorithm.cmd.sub;

import com.github.yufiriamazenta.craftorithm.config.Languages;
import com.github.yufiriamazenta.craftorithm.config.PluginConfigs;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeFactory;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeManager;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeType;
Expand Down Expand Up @@ -52,6 +53,8 @@ private CreateRecipeCommand() {
if (!RecipeManager.INSTANCE.supportPotionMix()) {
unsupportedRecipeTypeList.add("potion");
}
if (!PluginConfigs.ENABLE_ANVIL_RECIPE.value())
unsupportedRecipeTypeList.add("anvil");
recipeTypeList.removeAll(unsupportedRecipeTypeList);
}

Expand Down Expand Up @@ -96,6 +99,9 @@ public boolean onCommand(CommandSender sender, List<String> args) {
case POTION:
openPotionMixCreator((Player) sender, recipeType, recipeName);
break;
case ANVIL:
openAnvilRecipeCreator((Player) sender, recipeType, recipeName);
break;
default:
LangUtil.sendLang(sender, Languages.COMMAND_CREATE_UNSUPPORTED_RECIPE_TYPE.value());
break;
Expand Down Expand Up @@ -490,6 +496,69 @@ private void openPotionMixCreator(Player player, RecipeType recipeType, String r
potionMixCreator.openMenu();
}

private void openAnvilRecipeCreator(Player player, RecipeType recipeType, String recipeName) {
StoredMenu anvilRecipeCreator = new StoredMenu(player, new MenuDisplay(
Languages.MENU_RECIPE_CREATOR_TITLE.value()
.replace("<recipe_type>", recipeType.name())
.replace("<recipe_name>", recipeName),
new MenuLayout(Arrays.asList(
"#########",
"#***#%%%#",
"# * A% %#",
"#***#%%%#",
"####B####"
), () -> {
Map<Character, Icon> layoutMap = new HashMap<>();
layoutMap.put('#', getFrameIcon());
layoutMap.put('%', getResultFrameIcon());
layoutMap.put('*', new Icon(Material.CYAN_STAINED_GLASS_PANE, Languages.MENU_RECIPE_CREATOR_ICON_ANVIL_FRAME.value()));
Icon toggleCopyNbt = new Icon(
Material.NAME_TAG,
Languages.MENU_RECIPE_CREATOR_ICON_ANVIL_COPY_NBT_TOGGLE.value(),
event -> setIconGlowing(event.getSlot(), event)
);
toggleCopyNbt.display().addUnsafeEnchantment(Enchantment.MENDING, 1);
toggleCopyNbt.display().addItemFlags(ItemFlag.HIDE_ENCHANTS);
layoutMap.put('B', toggleCopyNbt);
layoutMap.put('A', new Icon(Material.ANVIL, Languages.MENU_RECIPE_CREATOR_ICON_CONFIRM.value(),
event -> {
StoredMenu creator = (StoredMenu) event.getClickedInventory().getHolder();
ItemStack result = Objects.requireNonNull(creator).storedItems().get(24);
ItemStack base = creator.storedItems().get(19);
ItemStack addition = creator.storedItems().get(21);
if (ItemUtil.isAir(result)) {
LangUtil.sendLang(event.getWhoClicked(), Languages.COMMAND_CREATE_NULL_RESULT.value());
return;
}
if (ItemUtil.isAir(addition) || ItemUtil.isAir(base)) {
LangUtil.sendLang(event.getWhoClicked(), Languages.COMMAND_CREATE_NULL_SOURCE.value());
return;
}
String resultName = ItemUtils.matchItemNameOrCreate(result, false);
String inputName = ItemUtils.matchItemNameOrCreate(base, true);
String ingredientName = ItemUtils.matchItemNameOrCreate(addition, true);
YamlConfigWrapper recipeConfig = createRecipeConfig(recipeName);
recipeConfig.set("source.copy_nbt", event.getInventory().getItem(40).getItemMeta().hasEnchants());
recipeConfig.set("type", "anvil");
recipeConfig.set("source.base", inputName);
recipeConfig.set("source.addition", ingredientName);
recipeConfig.set("result", resultName);
recipeConfig.saveConfig();
recipeConfig.reloadConfig();
for (RecipeRegistry recipeRegistry : RecipeFactory.newRecipeRegistry(recipeConfig.config(), recipeName)) {
recipeRegistry.register();
}
RecipeManager.INSTANCE.recipeConfigWrapperMap().put(recipeName, recipeConfig);
event.getWhoClicked().closeInventory();
sendSuccessMsg(player, recipeType, recipeName);
})
);
return layoutMap;
})
));
anvilRecipeCreator.openMenu();
}

private void sendSuccessMsg(HumanEntity receiver, RecipeType recipeType, String recipeName) {
LangUtil.sendLang(
receiver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class Languages {
public static final StringConfigEntry MENU_RECIPE_CREATOR_ICON_COOKING_FRAME = new StringConfigEntry("menu.recipe_creator.icon.cooking_frame", "&a烧炼原料");
public static final StringConfigEntry MENU_RECIPE_CREATOR_ICON_SMITHING_FRAME = new StringConfigEntry("menu.recipe_creator.icon.smithing_frame", "&a锻造原料");
public static final StringConfigEntry MENU_RECIPE_CREATOR_ICON_POTION_FRAME = new StringConfigEntry("menu.recipe_creator.icon.potion_frame", "&a酿造原料");
public static final StringConfigEntry MENU_RECIPE_CREATOR_ICON_ANVIL_FRAME = new StringConfigEntry("menu.recipe_creator.icon.anvil_frame", "&a打造原料");
public static final StringConfigEntry MENU_RECIPE_CREATOR_ICON_ANVIL_COPY_NBT_TOGGLE = new StringConfigEntry("menu.recipe_creator.icon.anvil_copy_nbt_toggle", "&a是否保留物品NBT");
public static final StringConfigEntry MENU_RECIPE_CREATOR_ICON_FURNACE_TOGGLE = new StringConfigEntry("menu.recipe_creator.icon.furnace_toggle", "&a熔炉配方");
public static final StringConfigEntry MENU_RECIPE_CREATOR_ICON_BLASTING_TOGGLE = new StringConfigEntry("menu.recipe_creator.icon.blasting_toggle", "&a高炉配方");
public static final StringConfigEntry MENU_RECIPE_CREATOR_ICON_SMOKING_TOGGLE = new StringConfigEntry("menu.recipe_creator.icon.smoking_toggle", "&a烟熏炉配方");
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ menu:
cooking_frame: '&a烧炼原料'
smithing_frame: '&a锻造物品'
potion_frame: '&a酿造原料'
anvil_frame: '&a打造原料'
anvil_copy_nbt_toggle: '&a是否保留物品NBT'
furnace_toggle: '&a熔炉配方'
blasting_toggle: '&a高炉配方'
smoking_toggle: '&a烟熏炉配方'
Expand Down

0 comments on commit cc0d42f

Please sign in to comment.