From 36ded4ce9fdb3831550529d30048ba7e94f929ea Mon Sep 17 00:00:00 2001 From: dragontamerfred Date: Wed, 2 Oct 2019 16:48:21 +0200 Subject: [PATCH] Add Crafting tweaks. --- README.md | 9 +++- .../CraftingTweaks/CraftingTweaks.java | 50 +++++++++++++++++++ .../vanillatweaks/VanillaTweaks.java | 24 ++++----- .../nl/kallestruik/vanillatweaks/config.java | 16 ++++++ src/main/resources/config.yml | 10 +++- 5 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 src/main/java/nl/kallestruik/vanillatweaks/CraftingTweaks/CraftingTweaks.java diff --git a/README.md b/README.md index 68017f6..5f7cf4b 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,15 @@ A list of all the tweaks current present in this project. Allows players to use the command `/toggletrample` to toggle their ability to trample farmland. This tweak also disables crop trampling for villagers and iron golems to help with decorative villages. +### Crafting tweaks +Adds some extra crafting recipes to the game. +Currently included: +- 8 wood logs -> 4 chests +- 2 paper + 1 iron ingot -> 1 name tag +- 1 wool (any color) -> 4 string +- 3 leather + 2 string + 2 iron ingot -> 1 saddle + ## Planned tweaks -- Crafting tweaks - Dynamite - Seed drop planting - Sign editing diff --git a/src/main/java/nl/kallestruik/vanillatweaks/CraftingTweaks/CraftingTweaks.java b/src/main/java/nl/kallestruik/vanillatweaks/CraftingTweaks/CraftingTweaks.java new file mode 100644 index 0000000..ce9efeb --- /dev/null +++ b/src/main/java/nl/kallestruik/vanillatweaks/CraftingTweaks/CraftingTweaks.java @@ -0,0 +1,50 @@ +package nl.kallestruik.vanillatweaks.CraftingTweaks; + +import nl.kallestruik.vanillatweaks.config; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.RecipeChoice; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ShapelessRecipe; +import org.bukkit.plugin.java.JavaPlugin; + +public class CraftingTweaks { + + public static void init(JavaPlugin plugin) { + RecipeChoice woodLog = new RecipeChoice.MaterialChoice(Material.OAK_LOG, Material.BIRCH_LOG, Material.SPRUCE_LOG, Material.JUNGLE_LOG, Material.ACACIA_LOG, Material.DARK_OAK_LOG); + RecipeChoice allWool = new RecipeChoice.MaterialChoice(Material.WHITE_WOOL, Material.BLACK_WOOL, Material.BLUE_WOOL, Material.BROWN_WOOL, Material.CYAN_WOOL, Material.GRAY_WOOL, Material.GREEN_WOOL, Material.LIGHT_BLUE_WOOL, Material.LIGHT_GRAY_WOOL, Material.LIME_WOOL, Material.MAGENTA_WOOL, Material.ORANGE_WOOL, Material.PINK_WOOL, Material.PURPLE_WOOL, Material.RED_WOOL, Material.YELLOW_WOOL); + + // Better chest recipe + NamespacedKey chestKey = new NamespacedKey(plugin, "chest"); + ShapedRecipe chestRecipe = new ShapedRecipe(chestKey, new ItemStack(Material.CHEST, 4)); + chestRecipe.shape("WWW", "W W", "WWW"); + chestRecipe.setIngredient('W', woodLog); + + // Name tag recipe + NamespacedKey nametagKey = new NamespacedKey(plugin, "nametag"); + ShapedRecipe nametagRecipe = new ShapedRecipe(nametagKey, new ItemStack(Material.NAME_TAG)); + nametagRecipe.shape(" I", " P ", "P "); + nametagRecipe.setIngredient('I', Material.IRON_INGOT); + nametagRecipe.setIngredient('P', Material.PAPER); + + // Wool > String recipe + NamespacedKey stringKey = new NamespacedKey(plugin, "string"); + ShapelessRecipe stringRecipe = new ShapelessRecipe(stringKey, new ItemStack(Material.STRING, 4)); + stringRecipe.addIngredient(allWool); + + // Saddle + NamespacedKey saddleKey = new NamespacedKey(plugin, "saddle"); + ShapedRecipe saddleRecipe = new ShapedRecipe(saddleKey, new ItemStack(Material.SADDLE)); + saddleRecipe.shape("LLL", "S S", "I I"); + saddleRecipe.setIngredient('L', Material.LEATHER); + saddleRecipe.setIngredient('S', Material.STRING); + saddleRecipe.setIngredient('I', Material.IRON_INGOT); + + // Add recipes + if (config.CRAFTING_TWEAKS_BETTER_CHEST) plugin.getServer().addRecipe(chestRecipe); + if (config.CRAFTING_TWEAKS_NAME_TAG) plugin.getServer().addRecipe(nametagRecipe); + if (config.CRAFTING_TWEAKS_WOOL_TO_STRING) plugin.getServer().addRecipe(stringRecipe); + if (config.CRAFTING_TWEAKS_SADDLE) plugin.getServer().addRecipe(saddleRecipe); + } +} diff --git a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java index 2b62e4a..711c62f 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java @@ -1,5 +1,6 @@ package nl.kallestruik.vanillatweaks; +import nl.kallestruik.vanillatweaks.CraftingTweaks.CraftingTweaks; import nl.kallestruik.vanillatweaks.ToggleTrample.CommandToggletrample; import nl.kallestruik.vanillatweaks.ToggleTrample.TrampleHandler; import org.bukkit.configuration.InvalidConfigurationException; @@ -15,22 +16,15 @@ public final class VanillaTweaks extends JavaPlugin { // Config loading config.load(new File(this.getDataFolder(), c.CONFIG_FILE_NAME)); - /** - * Toggle trample - * - * Enable/disable your ability to trample crops with a simple command. Also stops villagers and iron golems - * from trampling your crops. - */ - TrampleHandler.loadTrampleEnabled(new File(this.getDataFolder(), c.TRAMPLE_ENABLED_FILE_NAME)); - getServer().getPluginCommand("toggletrample").setExecutor(new CommandToggletrample()); - getServer().getPluginManager().registerEvents(new TrampleHandler(), this); + if (config.TOGGLE_TRAMPLE_ENABLED) { + TrampleHandler.loadTrampleEnabled(new File(this.getDataFolder(), c.TRAMPLE_ENABLED_FILE_NAME)); + getServer().getPluginCommand("toggletrample").setExecutor(new CommandToggletrample()); + getServer().getPluginManager().registerEvents(new TrampleHandler(), this); + } - /** - * Crafting - * - * Add some extra crafting recipes to the game. Examples: 8 logs -> 4 chests, 1 wool -> 4 string, - * 8 stairs instead of 6, 2 paper + 1 iron -> name tag. - */ + if (config.CRAFTING_TWEAKS_ENABLED) { + CraftingTweaks.init(this); + } /** * Dynamite diff --git a/src/main/java/nl/kallestruik/vanillatweaks/config.java b/src/main/java/nl/kallestruik/vanillatweaks/config.java index 528cd1d..c5e73c7 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/config.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/config.java @@ -9,6 +9,11 @@ import java.io.IOException; public class config { public static boolean TOGGLE_TRAMPLE_ENABLED; + public static boolean CRAFTING_TWEAKS_ENABLED; + public static boolean CRAFTING_TWEAKS_BETTER_CHEST; + public static boolean CRAFTING_TWEAKS_NAME_TAG; + public static boolean CRAFTING_TWEAKS_WOOL_TO_STRING; + public static boolean CRAFTING_TWEAKS_SADDLE; public static void load(File file) throws IOException, InvalidConfigurationException { if (!file.getParentFile().exists()) @@ -20,5 +25,16 @@ public class config { TOGGLE_TRAMPLE_ENABLED = config.getBoolean("toggle-trample.enabled"); + CRAFTING_TWEAKS_ENABLED = config.getBoolean("crafting-tweaks.enabled"); + CRAFTING_TWEAKS_BETTER_CHEST = config.getBoolean("crafting-tweaks.better-chest"); + CRAFTING_TWEAKS_NAME_TAG = config.getBoolean("crafting-tweaks.name-tag"); + CRAFTING_TWEAKS_WOOL_TO_STRING = config.getBoolean("crafting-tweaks.wool-to-string"); + CRAFTING_TWEAKS_SADDLE = config.getBoolean("crafting-tweaks.saddle"); + + + + + + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ec7287e..e93ebea 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,2 +1,10 @@ toggle-trample: - enabled: true \ No newline at end of file + enabled: true + +crafting-tweaks: + enabled: true + better-chest: true + name-tag: true + wool-to-string: true + saddle: true +