generated from PurpurMC/Tentacles
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance raw ore smelting to allow per-world toggling
- Loading branch information
1 parent
378d7c9
commit f980d08
Showing
3 changed files
with
164 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ From: MrFishCakes <[email protected]> | |
Date: Tue, 18 Jul 2023 18:56:10 +0100 | ||
Subject: [PATCH] Allow custom raw ore block smelting recipes | ||
|
||
This patch allows for custom furnace and blasting recipes for raw ore blocks. They can be smelted in a 1:X ratio, cook time and experience can be customised for each different recipe | ||
This patch allows for custom furnace and blasting recipes for raw ore blocks. Each block will yeild 9 ingots | ||
|
||
diff --git a/src/main/java/dev/graphitemc/graphite/GraphiteConfig.java b/src/main/java/dev/graphitemc/graphite/GraphiteConfig.java | ||
index 387ba01bfa1fa6606fc7582ba3da1d1185380b29..42ed14d8ad391208c879e7c2fcfc084798acf491 100644 | ||
index 387ba01bfa1fa6606fc7582ba3da1d1185380b29..d2710d19fa92d797611c431ede28366a84498770 100644 | ||
--- a/src/main/java/dev/graphitemc/graphite/GraphiteConfig.java | ||
+++ b/src/main/java/dev/graphitemc/graphite/GraphiteConfig.java | ||
@@ -6,19 +6,22 @@ import dev.graphitemc.graphite.command.GraphiteCommand; | ||
|
@@ -35,47 +35,51 @@ index 387ba01bfa1fa6606fc7582ba3da1d1185380b29..42ed14d8ad391208c879e7c2fcfc0847 | |
import java.util.logging.Level; | ||
|
||
public class GraphiteConfig { | ||
@@ -150,4 +153,106 @@ public class GraphiteConfig { | ||
@@ -150,4 +153,122 @@ public class GraphiteConfig { | ||
return builder.build(); | ||
} | ||
|
||
+ private static void smeltRawCopperBlocks() { | ||
+ ConfigurationSection rawCopperBlockSection = config.getConfigurationSection("recipes.raw-ore-smelting.raw-copper-block"); | ||
+ if (rawCopperBlockSection == null) { | ||
+ set("recipes.raw-ore-smelting.raw-copper-block.furnace.enabled", true); | ||
+ set("recipes.raw-ore-smelting.raw-copper-block.furnace.experience", 9.0D); | ||
+ set("recipes.raw-ore-smelting.raw-copper-block.furnace.experience", 6.3D); | ||
+ set("recipes.raw-ore-smelting.raw-copper-block.furnace.cook-time", 1800); | ||
+ | ||
+ set("recipes.raw-ore-smelting.raw-copper-block.blasting.enabled", true); | ||
+ set("recipes.raw-ore-smelting.raw-copper-block.blasting.experience", 9.0D); | ||
+ set("recipes.raw-ore-smelting.raw-copper-block.blasting.experience", 6.3D); | ||
+ set("recipes.raw-ore-smelting.raw-copper-block.blasting.cook-time", 900); | ||
+ } | ||
+ | ||
+ NamespacedKey furnaceKey = new NamespacedKey(NamespacedKey.BUKKIT, "raw_copper_block_furnace"); | ||
+ NamespacedKey blastingKey = new NamespacedKey(NamespacedKey.BUKKIT, "raw_copper_block_blasting"); | ||
+ NamespacedKey furnaceKey = new NamespacedKey("graphite", "raw_copper_block_furnace"); | ||
+ NamespacedKey blastingKey = new NamespacedKey("graphite", "raw_copper_block_blasting"); | ||
+ | ||
+ FurnaceRecipe furnaceRecipe = new FurnaceRecipe(furnaceKey, new ItemStack(Material.COPPER_BLOCK), Material.RAW_COPPER_BLOCK, | ||
+ FurnaceRecipe furnaceRecipe = new FurnaceRecipe(furnaceKey, new ItemStack(Material.COPPER_INGOT, 9), Material.RAW_COPPER_BLOCK, | ||
+ (float) getDouble("recipes.raw-ore-smelting.raw-copper-block.furnace.experience", 6.3D), | ||
+ getInt("recipes.raw-ore-smelting.raw-copper-block.furnace.cook-time", 1800)); | ||
+ | ||
+ BlastingRecipe blastingRecipe = new BlastingRecipe(blastingKey, new ItemStack(Material.COPPER_BLOCK), Material.RAW_COPPER_BLOCK, | ||
+ BlastingRecipe blastingRecipe = new BlastingRecipe(blastingKey, new ItemStack(Material.COPPER_INGOT, 9), Material.RAW_COPPER_BLOCK, | ||
+ (float) getDouble("recipes.raw-ore-smelting.raw-copper-block.blasting.experience", 6.3D), | ||
+ getInt("recipes.raw-ore-smelting.raw-copper-block.blasting.cook-time", 900)); | ||
+ | ||
+ if (getBoolean("recipes.raw-ore-smelting.raw-copper-block.furnace.enabled", true)) { | ||
+ if (!Bukkit.addRecipe(furnaceRecipe)) | ||
+ Bukkit.getLogger().log(Level.SEVERE, "Unable to add " + furnaceKey + " recipe"); | ||
+ if (Bukkit.getRecipe(furnaceKey) != null) { | ||
+ Bukkit.removeRecipe(furnaceKey); | ||
+ } | ||
+ | ||
+ Bukkit.addRecipe(furnaceRecipe); | ||
+ } | ||
+ | ||
+ if (getBoolean("recipes.raw-ore-smelting.raw-copper-block.blasting.enabled", true)) { | ||
+ if (!Bukkit.addRecipe(blastingRecipe)) | ||
+ Bukkit.getLogger().log(Level.SEVERE, "Unable to add " + blastingKey + " recipe"); | ||
+ if (Bukkit.getRecipe(blastingKey) != null) { | ||
+ Bukkit.removeRecipe(blastingKey); | ||
+ } | ||
+ | ||
+ Bukkit.addRecipe(blastingRecipe); | ||
+ } | ||
+ } | ||
+ | ||
+ private static void smeltRawGoldBlocks() { | ||
+ ConfigurationSection rawGoldBlockSection = config.getConfigurationSection("recipes.raw-ore-smelting.raw-gold-block"); | ||
+ if (rawGoldBlockSection == null) { | ||
+ ConfigurationSection rawCopperBlockSection = config.getConfigurationSection("recipes.raw-ore-smelting.raw-gold-block"); | ||
+ if (rawCopperBlockSection == null) { | ||
+ set("recipes.raw-ore-smelting.raw-gold-block.furnace.enabled", true); | ||
+ set("recipes.raw-ore-smelting.raw-gold-block.furnace.experience", 9.0D); | ||
+ set("recipes.raw-ore-smelting.raw-gold-block.furnace.cook-time", 1800); | ||
|
@@ -85,31 +89,37 @@ index 387ba01bfa1fa6606fc7582ba3da1d1185380b29..42ed14d8ad391208c879e7c2fcfc0847 | |
+ set("recipes.raw-ore-smelting.raw-gold-block.blasting.cook-time", 900); | ||
+ } | ||
+ | ||
+ NamespacedKey furnaceKey = new NamespacedKey(NamespacedKey.BUKKIT, "raw_gold_block_furnace"); | ||
+ NamespacedKey blastingKey = new NamespacedKey(NamespacedKey.BUKKIT, "raw_gold_block_blasting"); | ||
+ NamespacedKey furnaceKey = new NamespacedKey("graphite", "raw_gold_block_furnace"); | ||
+ NamespacedKey blastingKey = new NamespacedKey("graphite", "raw_gold_block_blasting"); | ||
+ | ||
+ FurnaceRecipe furnaceRecipe = new FurnaceRecipe(furnaceKey, new ItemStack(Material.GOLD_BLOCK), Material.RAW_GOLD_BLOCK, | ||
+ FurnaceRecipe furnaceRecipe = new FurnaceRecipe(furnaceKey, new ItemStack(Material.GOLD_INGOT, 9), Material.RAW_GOLD_BLOCK, | ||
+ (float) getDouble("recipes.raw-ore-smelting.raw-gold-block.furnace.experience", 9.0D), | ||
+ getInt("recipes.raw-ore-smelting.raw-gold-block.furnace.cook-time", 1800)); | ||
+ | ||
+ BlastingRecipe blastingRecipe = new BlastingRecipe(blastingKey, new ItemStack(Material.GOLD_BLOCK), Material.RAW_GOLD_BLOCK, | ||
+ BlastingRecipe blastingRecipe = new BlastingRecipe(blastingKey, new ItemStack(Material.GOLD_INGOT, 9), Material.RAW_GOLD_BLOCK, | ||
+ (float) getDouble("recipes.raw-ore-smelting.raw-gold-block.blasting.experience", 9.0D), | ||
+ getInt("recipes.raw-ore-smelting.raw-gold-block.blasting.cook-time", 900)); | ||
+ | ||
+ if (getBoolean("recipes.raw-ore-smelting.raw-gold-block.furnace.enabled", true)) { | ||
+ if (!Bukkit.addRecipe(furnaceRecipe)) | ||
+ Bukkit.getLogger().log(Level.SEVERE, "Unable to add " + furnaceKey + " recipe"); | ||
+ if (Bukkit.getRecipe(furnaceKey) != null) { | ||
+ Bukkit.removeRecipe(furnaceKey); | ||
+ } | ||
+ | ||
+ Bukkit.addRecipe(furnaceRecipe); | ||
+ } | ||
+ | ||
+ if (getBoolean("recipes.raw-ore-smelting.raw-gold-block.blasting.enabled", true)) { | ||
+ if (!Bukkit.addRecipe(blastingRecipe)) | ||
+ Bukkit.getLogger().log(Level.SEVERE, "Unable to add " + blastingKey + " recipe"); | ||
+ if (Bukkit.getRecipe(blastingKey) != null) { | ||
+ Bukkit.removeRecipe(blastingKey); | ||
+ } | ||
+ | ||
+ Bukkit.addRecipe(blastingRecipe); | ||
+ } | ||
+ } | ||
+ | ||
+ private static void smeltRawIronBlocks() { | ||
+ ConfigurationSection rawIronBlockSection = config.getConfigurationSection("recipes.raw-ore-smelting.raw-iron-block"); | ||
+ if (rawIronBlockSection == null) { | ||
+ ConfigurationSection rawCopperBlockSection = config.getConfigurationSection("recipes.raw-ore-smelting.raw-iron-block"); | ||
+ if (rawCopperBlockSection == null) { | ||
+ set("recipes.raw-ore-smelting.raw-iron-block.furnace.enabled", true); | ||
+ set("recipes.raw-ore-smelting.raw-iron-block.furnace.experience", 6.3D); | ||
+ set("recipes.raw-ore-smelting.raw-iron-block.furnace.cook-time", 1800); | ||
|
@@ -119,26 +129,139 @@ index 387ba01bfa1fa6606fc7582ba3da1d1185380b29..42ed14d8ad391208c879e7c2fcfc0847 | |
+ set("recipes.raw-ore-smelting.raw-iron-block.blasting.cook-time", 900); | ||
+ } | ||
+ | ||
+ NamespacedKey furnaceKey = new NamespacedKey(NamespacedKey.BUKKIT, "raw_iron_block_furnace"); | ||
+ NamespacedKey blastingKey = new NamespacedKey(NamespacedKey.BUKKIT, "raw_iron_block_blasting"); | ||
+ NamespacedKey furnaceKey = new NamespacedKey("graphite", "raw_iron_block_furnace"); | ||
+ NamespacedKey blastingKey = new NamespacedKey("graphite", "raw_iron_block_blasting"); | ||
+ | ||
+ FurnaceRecipe furnaceRecipe = new FurnaceRecipe(furnaceKey, new ItemStack(Material.IRON_BLOCK), Material.RAW_IRON_BLOCK, | ||
+ FurnaceRecipe furnaceRecipe = new FurnaceRecipe(furnaceKey, new ItemStack(Material.IRON_INGOT, 9), Material.RAW_IRON_BLOCK, | ||
+ (float) getDouble("recipes.raw-ore-smelting.raw-iron-block.furnace.experience", 6.3D), | ||
+ getInt("recipes.raw-ore-smelting.raw-iron-block.furnace.cook-time", 1800)); | ||
+ | ||
+ BlastingRecipe blastingRecipe = new BlastingRecipe(blastingKey, new ItemStack(Material.IRON_BLOCK), Material.RAW_IRON_BLOCK, | ||
+ BlastingRecipe blastingRecipe = new BlastingRecipe(blastingKey, new ItemStack(Material.IRON_INGOT, 9), Material.RAW_IRON_BLOCK, | ||
+ (float) getDouble("recipes.raw-ore-smelting.raw-iron-block.blasting.experience", 6.3D), | ||
+ getInt("recipes.raw-ore-smelting.raw-iron-block.blasting.cook-time", 900)); | ||
+ | ||
+ if (getBoolean("recipes.raw-ore-smelting.raw-iron-block.furnace.enabled", true)) { | ||
+ if (!Bukkit.addRecipe(furnaceRecipe)) | ||
+ Bukkit.getLogger().log(Level.SEVERE, "Unable to add " + furnaceKey + " recipe"); | ||
+ if (Bukkit.getRecipe(furnaceKey) != null) { | ||
+ Bukkit.removeRecipe(furnaceKey); | ||
+ } | ||
+ | ||
+ Bukkit.addRecipe(furnaceRecipe); | ||
+ } | ||
+ | ||
+ if (getBoolean("recipes.raw-ore-smelting.raw-iron-block.blasting.enabled", true)) { | ||
+ if (!Bukkit.addRecipe(blastingRecipe)) | ||
+ Bukkit.getLogger().log(Level.SEVERE, "Unable to add " + blastingKey + " recipe"); | ||
+ if (Bukkit.getRecipe(blastingKey) != null) { | ||
+ Bukkit.removeRecipe(blastingKey); | ||
+ } | ||
+ | ||
+ Bukkit.addRecipe(blastingRecipe); | ||
+ } | ||
+ } | ||
+ | ||
} | ||
diff --git a/src/main/java/dev/graphitemc/graphite/GraphiteWorldConfig.java b/src/main/java/dev/graphitemc/graphite/GraphiteWorldConfig.java | ||
index adff342f7587c99375e3064fd5bea0f1ae9e2b33..a90edc0c9b4da596e4608cbc8cf3ab04c09d0f2f 100644 | ||
--- a/src/main/java/dev/graphitemc/graphite/GraphiteWorldConfig.java | ||
+++ b/src/main/java/dev/graphitemc/graphite/GraphiteWorldConfig.java | ||
@@ -116,4 +116,20 @@ public class GraphiteWorldConfig { | ||
return config.getList("world-settings." + path, Collections.emptyList()); | ||
} | ||
|
||
+ public boolean allowRawCopperSmelting = true; | ||
+ public boolean allowRawCopperBlasting = true; | ||
+ public boolean allowRawGoldSmelting = true; | ||
+ public boolean allowRawGoldBlasting = true; | ||
+ public boolean allowRawIronSmelting = true; | ||
+ public boolean allowRawIronBlasting = true; | ||
+ | ||
+ private void rawOreBlockSmelting() { | ||
+ allowRawCopperSmelting = getBoolean("recipes.raw-ore-smelting.raw-copper-block.furnace.enabled", true); | ||
+ allowRawCopperBlasting = getBoolean("recipes.raw-ore-smelting.raw-copper-block.blasting.enabled", true); | ||
+ allowRawGoldSmelting = getBoolean("recipes.raw-ore-smelting.raw-gold-block.furnace.enabled", true); | ||
+ allowRawGoldBlasting = getBoolean("recipes.raw-ore-smelting.raw-gold-block.blasting.enabled", true); | ||
+ allowRawIronSmelting = getBoolean("recipes.raw-ore-smelting.raw-iron-block.furnace.enabled", true); | ||
+ allowRawIronBlasting = getBoolean("recipes.raw-ore-smelting.raw-iron-block.blasting.enabled", true); | ||
+ } | ||
+ | ||
} | ||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java | ||
index 997d0fab71eacc6466ffe3bc8f6349e5813d6d49..8f079cd2a5b441dba5036505e4e5c34663466d4b 100644 | ||
--- a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java | ||
+++ b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java | ||
@@ -374,7 +374,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit | ||
|
||
int i = blockEntity.getMaxStackSize(); | ||
|
||
- if (!blockEntity.isLit() && AbstractFurnaceBlockEntity.canBurn(world.registryAccess(), irecipe, blockEntity.items, i)) { | ||
+ if (!blockEntity.isLit() && AbstractFurnaceBlockEntity.canBurn(world.registryAccess(), irecipe, blockEntity.items, i, blockEntity)) { // Graphite - Pass AbstractFurnaceBlockEntity | ||
// CraftBukkit start | ||
CraftItemStack fuel = CraftItemStack.asCraftMirror(itemstack); | ||
|
||
@@ -403,7 +403,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit | ||
} | ||
} | ||
|
||
- if (blockEntity.isLit() && AbstractFurnaceBlockEntity.canBurn(world.registryAccess(), irecipe, blockEntity.items, i)) { | ||
+ if (blockEntity.isLit() && AbstractFurnaceBlockEntity.canBurn(world.registryAccess(), irecipe, blockEntity.items, i, blockEntity)) { // Graphite - Pass AbstractFurnaceBlockEntity | ||
// CraftBukkit start | ||
if (irecipe != null && blockEntity.cookingProgress == 0) { | ||
CraftItemStack source = CraftItemStack.asCraftMirror(blockEntity.items.get(0)); | ||
@@ -444,10 +444,49 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit | ||
if (usedLavaFromUnderneath) blockEntity.items.set(1, ItemStack.EMPTY); // Purpur | ||
} | ||
|
||
- private static boolean canBurn(RegistryAccess registryManager, @Nullable Recipe<?> recipe, NonNullList<ItemStack> slots, int count) { | ||
+ // Graphite start - Check for custom smelting recipes | ||
+ private static boolean canBurnGraphite(CookingRecipe<?> recipe, AbstractFurnaceBlockEntity blockEntity) { | ||
+ if (!"graphite".equalsIgnoreCase(recipe.getKey().getNamespace())) return true; | ||
+ org.bukkit.Material inputMaterial = blockEntity.items.get(0).asBukkitMirror().getType(); | ||
+ | ||
+ if (blockEntity instanceof BlastFurnaceBlockEntity blastBlockEntity) { | ||
+ switch (inputMaterial) { | ||
+ case RAW_COPPER_BLOCK -> { | ||
+ return blastBlockEntity.level.graphiteConfig.allowRawCopperBlasting; | ||
+ } | ||
+ | ||
+ case RAW_GOLD_BLOCK -> { | ||
+ return blastBlockEntity.level.graphiteConfig.allowRawGoldBlasting; | ||
+ } | ||
+ | ||
+ case RAW_IRON_BLOCK -> { | ||
+ return blastBlockEntity.level.graphiteConfig.allowRawIronBlasting; | ||
+ } | ||
+ } | ||
+ } else if (blockEntity instanceof FurnaceBlockEntity furnaceBlockEntity) { | ||
+ switch (inputMaterial) { | ||
+ case RAW_COPPER_BLOCK -> { | ||
+ return furnaceBlockEntity.level.graphiteConfig.allowRawCopperSmelting; | ||
+ } | ||
+ | ||
+ case RAW_GOLD_BLOCK -> { | ||
+ return furnaceBlockEntity.level.graphiteConfig.allowRawGoldSmelting; | ||
+ } | ||
+ | ||
+ case RAW_IRON_BLOCK -> { | ||
+ return furnaceBlockEntity.level.graphiteConfig.allowRawIronSmelting; | ||
+ } | ||
+ } | ||
+ } | ||
+ | ||
+ return false; | ||
+ } | ||
+ // Graphite end - Check for custom smelting recipes | ||
+ private static boolean canBurn(RegistryAccess registryManager, @Nullable Recipe<?> recipe, NonNullList<ItemStack> slots, int count, AbstractFurnaceBlockEntity blockEntity) { // Graphite - Pass AbstractFurnaceBlockEntity | ||
if (!((ItemStack) slots.get(0)).isEmpty() && recipe != null) { | ||
ItemStack itemstack = recipe.getResultItem(registryManager); | ||
|
||
+ if (!AbstractFurnaceBlockEntity.canBurnGraphite((CookingRecipe<?>) recipe.toBukkitRecipe(), blockEntity)) return false; // Graphite | ||
if (itemstack.isEmpty()) { | ||
return false; | ||
} else { | ||
@@ -461,7 +500,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit | ||
} | ||
|
||
private static boolean burn(Level world, BlockPos blockposition, RegistryAccess iregistrycustom, @Nullable Recipe<?> irecipe, NonNullList<ItemStack> nonnulllist, int i) { // CraftBukkit | ||
- if (irecipe != null && AbstractFurnaceBlockEntity.canBurn(iregistrycustom, irecipe, nonnulllist, i)) { | ||
+ if (irecipe != null && AbstractFurnaceBlockEntity.canBurn(iregistrycustom, irecipe, nonnulllist, i, (AbstractFurnaceBlockEntity) world.getBlockEntity(blockposition))) { // Graphite - Pass AbstractFurnaceBlockEntity | ||
ItemStack itemstack = (ItemStack) nonnulllist.get(0); | ||
ItemStack itemstack1 = irecipe.getResultItem(iregistrycustom); | ||
ItemStack itemstack2 = (ItemStack) nonnulllist.get(2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters