From c611633b1c969da63c8d872fee10f4c04da69d6f Mon Sep 17 00:00:00 2001
From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com>
Date: Mon, 25 Mar 2024 18:07:24 -0700
Subject: [PATCH] Add compressed hammer item and recipe code
---
.../exdeorum/item/CompressedHammerItem.java | 53 +++++++++++++++++++
.../exdeorum/item/HammerItem.java | 9 ++--
.../exdeorum/recipe/RecipeUtil.java | 11 +++-
.../recipe/hammer/CompressedHammerRecipe.java | 51 ++++++++++++++++++
.../FinishedCompressedHammerRecipe.java | 37 +++++++++++++
.../exdeorum/recipe/hammer/HammerRecipe.java | 12 ++---
.../exdeorum/registry/EItems.java | 14 +++++
.../exdeorum/registry/ERecipeSerializers.java | 2 +
.../exdeorum/registry/ERecipeTypes.java | 2 +
9 files changed, 180 insertions(+), 11 deletions(-)
create mode 100644 src/main/java/thedarkcolour/exdeorum/item/CompressedHammerItem.java
create mode 100644 src/main/java/thedarkcolour/exdeorum/recipe/hammer/CompressedHammerRecipe.java
create mode 100644 src/main/java/thedarkcolour/exdeorum/recipe/hammer/FinishedCompressedHammerRecipe.java
diff --git a/src/main/java/thedarkcolour/exdeorum/item/CompressedHammerItem.java b/src/main/java/thedarkcolour/exdeorum/item/CompressedHammerItem.java
new file mode 100644
index 00000000..84c102ff
--- /dev/null
+++ b/src/main/java/thedarkcolour/exdeorum/item/CompressedHammerItem.java
@@ -0,0 +1,53 @@
+/*
+ * Ex Deorum
+ * Copyright (c) 2024 thedarkcolour
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package thedarkcolour.exdeorum.item;
+
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.Tier;
+import net.minecraft.world.item.crafting.RecipeType;
+import net.minecraft.world.level.block.Block;
+import net.minecraftforge.common.util.Lazy;
+import org.jetbrains.annotations.Nullable;
+import thedarkcolour.exdeorum.recipe.RecipeUtil;
+import thedarkcolour.exdeorum.registry.EItems;
+
+import java.util.Set;
+
+// todo implement
+public class CompressedHammerItem extends HammerItem {
+ public static Lazy> validBlocks = Lazy.of(() -> HammerItem.computeValidBlocks(RecipeUtil.getCachedCompressedHammerRecipes()));
+
+ public static void refreshValidBlocks() {
+ validBlocks = Lazy.of(() -> HammerItem.computeValidBlocks(RecipeUtil.getCachedCompressedHammerRecipes()));
+ }
+
+ public CompressedHammerItem(Tier tier, Properties properties) {
+ super(tier, properties);
+ }
+
+ @Override
+ protected Set getValidBlocks() {
+ return validBlocks.get();
+ }
+
+ @Override
+ public int getBurnTime(ItemStack stack, @Nullable RecipeType> recipeType) {
+ return this == EItems.WOODEN_COMPRESSED_HAMMER.get() ? 200 : 0;
+ }
+}
diff --git a/src/main/java/thedarkcolour/exdeorum/item/HammerItem.java b/src/main/java/thedarkcolour/exdeorum/item/HammerItem.java
index 6014e1f7..af42cfaa 100644
--- a/src/main/java/thedarkcolour/exdeorum/item/HammerItem.java
+++ b/src/main/java/thedarkcolour/exdeorum/item/HammerItem.java
@@ -30,19 +30,20 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.util.Lazy;
import org.jetbrains.annotations.Nullable;
import thedarkcolour.exdeorum.recipe.RecipeUtil;
+import thedarkcolour.exdeorum.recipe.hammer.HammerRecipe;
import thedarkcolour.exdeorum.registry.EItems;
+import java.util.Collection;
import java.util.Set;
public class HammerItem extends DiggerItem {
- public static Lazy> validBlocks = Lazy.of(HammerItem::computeValidBlocks);
+ public static Lazy> validBlocks = Lazy.of(() -> computeValidBlocks(RecipeUtil.getCachedHammerRecipes()));
public HammerItem(Tier tier, Properties properties) {
super(1.0f, -2.8f, tier, null, properties);
}
- public static Set computeValidBlocks() {
- var hammerRecipes = RecipeUtil.getCachedHammerRecipes();
+ public static Set computeValidBlocks(Collection extends HammerRecipe> hammerRecipes) {
var validBlocks = new ObjectOpenHashSet(hammerRecipes.size());
for (var recipe : hammerRecipes) {
@@ -57,7 +58,7 @@ public class HammerItem extends DiggerItem {
}
public static void refreshValidBlocks() {
- validBlocks = Lazy.of(HammerItem::computeValidBlocks);
+ validBlocks = Lazy.of(() -> computeValidBlocks(RecipeUtil.getCachedHammerRecipes()));
}
protected Set getValidBlocks() {
diff --git a/src/main/java/thedarkcolour/exdeorum/recipe/RecipeUtil.java b/src/main/java/thedarkcolour/exdeorum/recipe/RecipeUtil.java
index cbb4cda3..9d73955e 100644
--- a/src/main/java/thedarkcolour/exdeorum/recipe/RecipeUtil.java
+++ b/src/main/java/thedarkcolour/exdeorum/recipe/RecipeUtil.java
@@ -55,6 +55,7 @@ import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;
import thedarkcolour.exdeorum.ExDeorum;
import thedarkcolour.exdeorum.compat.PreferredOres;
+import thedarkcolour.exdeorum.item.CompressedHammerItem;
import thedarkcolour.exdeorum.item.HammerItem;
import thedarkcolour.exdeorum.loot.SummationGenerator;
import thedarkcolour.exdeorum.recipe.barrel.BarrelCompostRecipe;
@@ -64,6 +65,7 @@ import thedarkcolour.exdeorum.recipe.barrel.BarrelMixingRecipe;
import thedarkcolour.exdeorum.recipe.cache.*;
import thedarkcolour.exdeorum.recipe.crook.CrookRecipe;
import thedarkcolour.exdeorum.recipe.crucible.CrucibleRecipe;
+import thedarkcolour.exdeorum.recipe.hammer.CompressedHammerRecipe;
import thedarkcolour.exdeorum.recipe.hammer.HammerRecipe;
import thedarkcolour.exdeorum.recipe.sieve.CompressedSieveRecipe;
import thedarkcolour.exdeorum.recipe.sieve.SieveRecipe;
@@ -87,6 +89,7 @@ public final class RecipeUtil {
private static SingleIngredientRecipeCache lavaCrucibleRecipeCache;
private static SingleIngredientRecipeCache waterCrucibleRecipeCache;
private static SingleIngredientRecipeCache hammerRecipeCache;
+ private static SingleIngredientRecipeCache compressedHammerRecipeCache;
private static SieveRecipeCache sieveRecipeCache;
private static SieveRecipeCache compressedSieveRecipeCache;
private static BarrelFluidMixingRecipeCache barrelFluidMixingRecipeCache;
@@ -99,6 +102,7 @@ public final class RecipeUtil {
lavaCrucibleRecipeCache = new SingleIngredientRecipeCache<>(recipes, ERecipeTypes.LAVA_CRUCIBLE);
waterCrucibleRecipeCache = new SingleIngredientRecipeCache<>(recipes, ERecipeTypes.WATER_CRUCIBLE);
hammerRecipeCache = new SingleIngredientRecipeCache<>(recipes, ERecipeTypes.HAMMER).trackAllRecipes();
+ compressedHammerRecipeCache = new SingleIngredientRecipeCache<>(recipes, ERecipeTypes.COMPRESSED_HAMMER).trackAllRecipes();
sieveRecipeCache = new SieveRecipeCache<>(recipes, ERecipeTypes.SIEVE);
compressedSieveRecipeCache = new SieveRecipeCache<>(recipes, ERecipeTypes.COMPRESSED_SIEVE);
barrelFluidMixingRecipeCache = new BarrelFluidMixingRecipeCache(recipes);
@@ -106,6 +110,7 @@ public final class RecipeUtil {
crookRecipeCache = new CrookRecipeCache(recipes);
crucibleHeatRecipeCache = new CrucibleHeatRecipeCache(recipes);
HammerItem.refreshValidBlocks();
+ CompressedHammerItem.refreshValidBlocks();
}
public static void unload() {
@@ -113,6 +118,7 @@ public final class RecipeUtil {
lavaCrucibleRecipeCache = null;
waterCrucibleRecipeCache = null;
hammerRecipeCache = null;
+ compressedHammerRecipeCache = null;
sieveRecipeCache = null;
barrelFluidMixingRecipeCache = null;
fluidTransformationRecipeCache = null;
@@ -152,6 +158,10 @@ public final class RecipeUtil {
return hammerRecipeCache.getAllRecipes();
}
+ public static Collection getCachedCompressedHammerRecipes() {
+ return compressedHammerRecipeCache.getAllRecipes();
+ }
+
public static > Collection byType(RecipeManager manager, RecipeType type) {
return manager.byType(type).values();
}
@@ -315,7 +325,6 @@ public final class RecipeUtil {
return barrelCompostRecipeCache != null && barrelCompostRecipeCache.getRecipe(stack) != null;
}
- // todo stop using the RecipeManager
@Nullable
public static BarrelMixingRecipe getBarrelMixingRecipe(RecipeManager recipes, ItemStack stack, FluidStack fluid) {
for (var recipe : byType(recipes, ERecipeTypes.BARREL_MIXING.get())) {
diff --git a/src/main/java/thedarkcolour/exdeorum/recipe/hammer/CompressedHammerRecipe.java b/src/main/java/thedarkcolour/exdeorum/recipe/hammer/CompressedHammerRecipe.java
new file mode 100644
index 00000000..2b697f4a
--- /dev/null
+++ b/src/main/java/thedarkcolour/exdeorum/recipe/hammer/CompressedHammerRecipe.java
@@ -0,0 +1,51 @@
+/*
+ * Ex Deorum
+ * Copyright (c) 2024 thedarkcolour
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package thedarkcolour.exdeorum.recipe.hammer;
+
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.crafting.Ingredient;
+import net.minecraft.world.item.crafting.RecipeSerializer;
+import net.minecraft.world.item.crafting.RecipeType;
+import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;
+import thedarkcolour.exdeorum.registry.ERecipeSerializers;
+import thedarkcolour.exdeorum.registry.ERecipeTypes;
+
+public class CompressedHammerRecipe extends HammerRecipe {
+ public CompressedHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount) {
+ super(id, ingredient, result, resultAmount);
+ }
+
+ @Override
+ public RecipeSerializer> getSerializer() {
+ return ERecipeSerializers.COMPRESSED_HAMMER.get();
+ }
+
+ @Override
+ public RecipeType> getType() {
+ return ERecipeTypes.COMPRESSED_HAMMER.get();
+ }
+
+ public static class Serializer extends HammerRecipe.AbstractSerializer {
+ @Override
+ protected CompressedHammerRecipe createHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount) {
+ return new CompressedHammerRecipe(id, ingredient, result, resultAmount);
+ }
+ }
+}
diff --git a/src/main/java/thedarkcolour/exdeorum/recipe/hammer/FinishedCompressedHammerRecipe.java b/src/main/java/thedarkcolour/exdeorum/recipe/hammer/FinishedCompressedHammerRecipe.java
new file mode 100644
index 00000000..960771e5
--- /dev/null
+++ b/src/main/java/thedarkcolour/exdeorum/recipe/hammer/FinishedCompressedHammerRecipe.java
@@ -0,0 +1,37 @@
+/*
+ * Ex Deorum
+ * Copyright (c) 2024 thedarkcolour
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package thedarkcolour.exdeorum.recipe.hammer;
+
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.crafting.Ingredient;
+import net.minecraft.world.item.crafting.RecipeSerializer;
+import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;
+import thedarkcolour.exdeorum.registry.ERecipeSerializers;
+
+public class FinishedCompressedHammerRecipe extends FinishedHammerRecipe {
+ public FinishedCompressedHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount) {
+ super(id, ingredient, result, resultAmount);
+ }
+
+ @Override
+ public RecipeSerializer> getType() {
+ return ERecipeSerializers.COMPRESSED_HAMMER.get();
+ }
+}
diff --git a/src/main/java/thedarkcolour/exdeorum/recipe/hammer/HammerRecipe.java b/src/main/java/thedarkcolour/exdeorum/recipe/hammer/HammerRecipe.java
index 265fe8d1..1c981c1b 100644
--- a/src/main/java/thedarkcolour/exdeorum/recipe/hammer/HammerRecipe.java
+++ b/src/main/java/thedarkcolour/exdeorum/recipe/hammer/HammerRecipe.java
@@ -49,11 +49,11 @@ public class HammerRecipe extends ProbabilityRecipe {
return ERecipeTypes.HAMMER.get();
}
- public static abstract class AbstractSerializer implements RecipeSerializer {
- protected abstract HammerRecipe createHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount);
+ public static abstract class AbstractSerializer implements RecipeSerializer {
+ protected abstract T createHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount);
@Override
- public HammerRecipe fromJson(ResourceLocation name, JsonObject json) {
+ public T fromJson(ResourceLocation name, JsonObject json) {
Ingredient ingredient = RecipeUtil.readIngredient(json, "ingredient");
Item result = RecipeUtil.readItem(json, "result");
NumberProvider resultAmount = RecipeUtil.readNumberProvider(json, "result_amount");
@@ -62,7 +62,7 @@ public class HammerRecipe extends ProbabilityRecipe {
@Override
@SuppressWarnings("deprecation")
- public HammerRecipe fromNetwork(ResourceLocation name, FriendlyByteBuf buffer) {
+ public T fromNetwork(ResourceLocation name, FriendlyByteBuf buffer) {
Ingredient ingredient = Ingredient.fromNetwork(buffer);
Item result = Objects.requireNonNull(buffer.readById(BuiltInRegistries.ITEM));
NumberProvider resultAmount = RecipeUtil.fromNetworkNumberProvider(buffer);
@@ -71,14 +71,14 @@ public class HammerRecipe extends ProbabilityRecipe {
@Override
@SuppressWarnings("deprecation")
- public void toNetwork(FriendlyByteBuf buffer, HammerRecipe recipe) {
+ public void toNetwork(FriendlyByteBuf buffer, T recipe) {
recipe.getIngredient().toNetwork(buffer);
buffer.writeId(BuiltInRegistries.ITEM, recipe.result);
RecipeUtil.toNetworkNumberProvider(buffer, recipe.resultAmount);
}
}
- public static class Serializer extends AbstractSerializer {
+ public static class Serializer extends AbstractSerializer {
@Override
protected HammerRecipe createHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount) {
return new HammerRecipe(id, ingredient, result, resultAmount);
diff --git a/src/main/java/thedarkcolour/exdeorum/registry/EItems.java b/src/main/java/thedarkcolour/exdeorum/registry/EItems.java
index 33768eca..1cc3bcc2 100644
--- a/src/main/java/thedarkcolour/exdeorum/registry/EItems.java
+++ b/src/main/java/thedarkcolour/exdeorum/registry/EItems.java
@@ -70,6 +70,14 @@ public class EItems {
public static final RegistryObject- DIAMOND_HAMMER = ITEMS.register("diamond_hammer", () -> new HammerItem(Tiers.DIAMOND, props()));
public static final RegistryObject
- NETHERITE_HAMMER = ITEMS.register("netherite_hammer", () -> new HammerItem(Tiers.NETHERITE, props()));
+ // Compressed Hammers
+ public static final RegistryObject
- WOODEN_COMPRESSED_HAMMER = ITEMS.register("wooden_compressed_hammer", () -> new CompressedHammerItem(Tiers.WOOD, props()));
+ public static final RegistryObject
- STONE_COMPRESSED_HAMMER = ITEMS.register("stone_compressed_hammer", () -> new CompressedHammerItem(Tiers.STONE, props()));
+ public static final RegistryObject
- GOLDEN_COMPRESSED_HAMMER = ITEMS.register("golden_compressed_hammer", () -> new CompressedHammerItem(Tiers.GOLD, props()));
+ public static final RegistryObject
- IRON_COMPRESSED_HAMMER = ITEMS.register("iron_compressed_hammer", () -> new CompressedHammerItem(Tiers.IRON, props()));
+ public static final RegistryObject
- DIAMOND_COMPRESSED_HAMMER = ITEMS.register("diamond_compressed_hammer", () -> new CompressedHammerItem(Tiers.DIAMOND, props()));
+ public static final RegistryObject
- NETHERITE_COMPRESSED_HAMMER = ITEMS.register("netherite_compressed_hammer", () -> new CompressedHammerItem(Tiers.NETHERITE, props()));
+
// Ore Chunks
public static final RegistryObject
- IRON_ORE_CHUNK = registerSimpleItem("iron_ore_chunk");
public static final RegistryObject
- COPPER_ORE_CHUNK = registerSimpleItem("copper_ore_chunk");
@@ -224,6 +232,12 @@ public class EItems {
output.accept(IRON_HAMMER.get());
output.accept(DIAMOND_HAMMER.get());
output.accept(NETHERITE_HAMMER.get());
+ output.accept(WOODEN_COMPRESSED_HAMMER.get());
+ output.accept(STONE_COMPRESSED_HAMMER.get());
+ output.accept(GOLDEN_COMPRESSED_HAMMER.get());
+ output.accept(IRON_COMPRESSED_HAMMER.get());
+ output.accept(DIAMOND_COMPRESSED_HAMMER.get());
+ output.accept(NETHERITE_COMPRESSED_HAMMER.get());
output.accept(IRON_ORE_CHUNK.get());
output.accept(COPPER_ORE_CHUNK.get());
output.accept(GOLD_ORE_CHUNK.get());
diff --git a/src/main/java/thedarkcolour/exdeorum/registry/ERecipeSerializers.java b/src/main/java/thedarkcolour/exdeorum/registry/ERecipeSerializers.java
index 3d32caae..bbdb63da 100644
--- a/src/main/java/thedarkcolour/exdeorum/registry/ERecipeSerializers.java
+++ b/src/main/java/thedarkcolour/exdeorum/registry/ERecipeSerializers.java
@@ -31,6 +31,7 @@ import thedarkcolour.exdeorum.recipe.barrel.BarrelMixingRecipe;
import thedarkcolour.exdeorum.recipe.crook.CrookRecipe;
import thedarkcolour.exdeorum.recipe.crucible.CrucibleHeatRecipe;
import thedarkcolour.exdeorum.recipe.crucible.CrucibleRecipe;
+import thedarkcolour.exdeorum.recipe.hammer.CompressedHammerRecipe;
import thedarkcolour.exdeorum.recipe.hammer.HammerRecipe;
import thedarkcolour.exdeorum.recipe.sieve.CompressedSieveRecipe;
import thedarkcolour.exdeorum.recipe.sieve.SieveRecipe;
@@ -44,6 +45,7 @@ public class ERecipeSerializers {
public static final RegistryObject> BARREL_FLUID_TRANSFORMATION = RECIPE_SERIALIZERS.register("barrel_fluid_transformation", FluidTransformationRecipe.Serializer::new);
public static final RegistryObject> HAMMER = RECIPE_SERIALIZERS.register("hammer", HammerRecipe.Serializer::new);
+ public static final RegistryObject> COMPRESSED_HAMMER = RECIPE_SERIALIZERS.register("compressed_hammer", CompressedHammerRecipe.Serializer::new);
public static final RegistryObject> CROOK = RECIPE_SERIALIZERS.register("crook", CrookRecipe.Serializer::new);
public static final RegistryObject> CRUCIBLE_HEAT_SOURCE = RECIPE_SERIALIZERS.register("crucible_heat_source", CrucibleHeatRecipe.Serializer::new);
diff --git a/src/main/java/thedarkcolour/exdeorum/registry/ERecipeTypes.java b/src/main/java/thedarkcolour/exdeorum/registry/ERecipeTypes.java
index 8446e748..3c94a7e2 100644
--- a/src/main/java/thedarkcolour/exdeorum/registry/ERecipeTypes.java
+++ b/src/main/java/thedarkcolour/exdeorum/registry/ERecipeTypes.java
@@ -30,6 +30,7 @@ import thedarkcolour.exdeorum.recipe.barrel.BarrelMixingRecipe;
import thedarkcolour.exdeorum.recipe.crook.CrookRecipe;
import thedarkcolour.exdeorum.recipe.crucible.CrucibleHeatRecipe;
import thedarkcolour.exdeorum.recipe.crucible.CrucibleRecipe;
+import thedarkcolour.exdeorum.recipe.hammer.CompressedHammerRecipe;
import thedarkcolour.exdeorum.recipe.hammer.HammerRecipe;
import thedarkcolour.exdeorum.recipe.sieve.CompressedSieveRecipe;
import thedarkcolour.exdeorum.recipe.sieve.SieveRecipe;
@@ -46,6 +47,7 @@ public class ERecipeTypes {
public static final RegistryObject> WATER_CRUCIBLE = RECIPE_TYPES.register("water_crucible", () -> RecipeType.simple(ERecipeTypes.WATER_CRUCIBLE.getId()));
public static final RegistryObject> HAMMER = RECIPE_TYPES.register("hammer", () -> RecipeType.simple(ERecipeTypes.HAMMER.getId()));
+ public static final RegistryObject> COMPRESSED_HAMMER = RECIPE_TYPES.register("compressed_hammer", () -> RecipeType.simple(ERecipeTypes.COMPRESSED_SIEVE.getId()));
public static final RegistryObject> CROOK = RECIPE_TYPES.register("crook", () -> RecipeType.simple(ERecipeTypes.CROOK.getId()));
public static final RegistryObject> CRUCIBLE_HEAT_SOURCE = RECIPE_TYPES.register("crucible_heat_source", () -> RecipeType.simple(ERecipeTypes.CRUCIBLE_HEAT_SOURCE.getId()));