Skip to content

Commit

Permalink
Enhance raw ore smelting to allow per-world toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFishCakes committed Jul 27, 2023
1 parent 378d7c9 commit f980d08
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 41 deletions.
193 changes: 158 additions & 35 deletions patches/server/0003-Allow-custom-raw-ore-block-smelting-recipes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
4 changes: 2 additions & 2 deletions patches/server/0004-Disable-reload-commands.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Disable reload commands
Disable all reload commands from Bukkit, Spigot, Paper, Purpur and Graphite

diff --git a/src/main/java/dev/graphitemc/graphite/GraphiteConfig.java b/src/main/java/dev/graphitemc/graphite/GraphiteConfig.java
index 42ed14d8ad391208c879e7c2fcfc084798acf491..98e56ba772d07be9f7cf4462467190756e956827 100644
index d2710d19fa92d797611c431ede28366a84498770..4d4411e75894924cb4781e31ec0f9ba67b66bcca 100644
--- a/src/main/java/dev/graphitemc/graphite/GraphiteConfig.java
+++ b/src/main/java/dev/graphitemc/graphite/GraphiteConfig.java
@@ -255,4 +255,10 @@ public class GraphiteConfig {
@@ -271,4 +271,10 @@ public class GraphiteConfig {
}
}

Expand Down
8 changes: 4 additions & 4 deletions patches/server/0005-Iron-Golems-attack-Creepers.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ Subject: [PATCH] Iron Golems attack Creepers
Iron Golems now have the ability to attack Creepers

diff --git a/src/main/java/dev/graphitemc/graphite/GraphiteWorldConfig.java b/src/main/java/dev/graphitemc/graphite/GraphiteWorldConfig.java
index adff342f7587c99375e3064fd5bea0f1ae9e2b33..8d3706d8d8a3d4770bc3bd813f3a00495cd287c8 100644
index a90edc0c9b4da596e4608cbc8cf3ab04c09d0f2f..f630c2d79ef9f951817fec217b985af9d28e85da 100644
--- a/src/main/java/dev/graphitemc/graphite/GraphiteWorldConfig.java
+++ b/src/main/java/dev/graphitemc/graphite/GraphiteWorldConfig.java
@@ -116,4 +116,10 @@ public class GraphiteWorldConfig {
return config.getList("world-settings." + path, Collections.emptyList());
@@ -132,4 +132,10 @@ public class GraphiteWorldConfig {
allowRawIronBlasting = getBoolean("recipes.raw-ore-smelting.raw-iron-block.blasting.enabled", true);
}

+ public boolean ironGolemsAttackCreepers;
+
+ private void ironGolemsTargetCreepers() {
+ private void ironGolemSettings() {
+ ironGolemsAttackCreepers = getBoolean("mobs.iron-golem.target-creepers", false);
+ }
+
Expand Down

0 comments on commit f980d08

Please sign in to comment.