Add compressed hammer item and recipe code
This commit is contained in:
parent
f33576e228
commit
c611633b1c
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Set<Block>> 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<Block> getValidBlocks() {
|
||||
return validBlocks.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBurnTime(ItemStack stack, @Nullable RecipeType<?> recipeType) {
|
||||
return this == EItems.WOODEN_COMPRESSED_HAMMER.get() ? 200 : 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Set<Block>> validBlocks = Lazy.of(HammerItem::computeValidBlocks);
|
||||
public static Lazy<Set<Block>> validBlocks = Lazy.of(() -> computeValidBlocks(RecipeUtil.getCachedHammerRecipes()));
|
||||
|
||||
public HammerItem(Tier tier, Properties properties) {
|
||||
super(1.0f, -2.8f, tier, null, properties);
|
||||
}
|
||||
|
||||
public static Set<Block> computeValidBlocks() {
|
||||
var hammerRecipes = RecipeUtil.getCachedHammerRecipes();
|
||||
public static Set<Block> computeValidBlocks(Collection<? extends HammerRecipe> hammerRecipes) {
|
||||
var validBlocks = new ObjectOpenHashSet<Block>(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<Block> getValidBlocks() {
|
||||
|
|
|
|||
|
|
@ -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<CrucibleRecipe> lavaCrucibleRecipeCache;
|
||||
private static SingleIngredientRecipeCache<CrucibleRecipe> waterCrucibleRecipeCache;
|
||||
private static SingleIngredientRecipeCache<HammerRecipe> hammerRecipeCache;
|
||||
private static SingleIngredientRecipeCache<CompressedHammerRecipe> compressedHammerRecipeCache;
|
||||
private static SieveRecipeCache<SieveRecipe> sieveRecipeCache;
|
||||
private static SieveRecipeCache<CompressedSieveRecipe> 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<CompressedHammerRecipe> getCachedCompressedHammerRecipes() {
|
||||
return compressedHammerRecipeCache.getAllRecipes();
|
||||
}
|
||||
|
||||
public static <C extends Container, T extends Recipe<C>> Collection<T> byType(RecipeManager manager, RecipeType<T> 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())) {
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<CompressedHammerRecipe> {
|
||||
@Override
|
||||
protected CompressedHammerRecipe createHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount) {
|
||||
return new CompressedHammerRecipe(id, ingredient, result, resultAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -49,11 +49,11 @@ public class HammerRecipe extends ProbabilityRecipe {
|
|||
return ERecipeTypes.HAMMER.get();
|
||||
}
|
||||
|
||||
public static abstract class AbstractSerializer implements RecipeSerializer<HammerRecipe> {
|
||||
protected abstract HammerRecipe createHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount);
|
||||
public static abstract class AbstractSerializer<T extends HammerRecipe> implements RecipeSerializer<T> {
|
||||
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<HammerRecipe> {
|
||||
@Override
|
||||
protected HammerRecipe createHammerRecipe(ResourceLocation id, Ingredient ingredient, Item result, NumberProvider resultAmount) {
|
||||
return new HammerRecipe(id, ingredient, result, resultAmount);
|
||||
|
|
|
|||
|
|
@ -70,6 +70,14 @@ public class EItems {
|
|||
public static final RegistryObject<Item> DIAMOND_HAMMER = ITEMS.register("diamond_hammer", () -> new HammerItem(Tiers.DIAMOND, props()));
|
||||
public static final RegistryObject<Item> NETHERITE_HAMMER = ITEMS.register("netherite_hammer", () -> new HammerItem(Tiers.NETHERITE, props()));
|
||||
|
||||
// Compressed Hammers
|
||||
public static final RegistryObject<Item> WOODEN_COMPRESSED_HAMMER = ITEMS.register("wooden_compressed_hammer", () -> new CompressedHammerItem(Tiers.WOOD, props()));
|
||||
public static final RegistryObject<Item> STONE_COMPRESSED_HAMMER = ITEMS.register("stone_compressed_hammer", () -> new CompressedHammerItem(Tiers.STONE, props()));
|
||||
public static final RegistryObject<Item> GOLDEN_COMPRESSED_HAMMER = ITEMS.register("golden_compressed_hammer", () -> new CompressedHammerItem(Tiers.GOLD, props()));
|
||||
public static final RegistryObject<Item> IRON_COMPRESSED_HAMMER = ITEMS.register("iron_compressed_hammer", () -> new CompressedHammerItem(Tiers.IRON, props()));
|
||||
public static final RegistryObject<Item> DIAMOND_COMPRESSED_HAMMER = ITEMS.register("diamond_compressed_hammer", () -> new CompressedHammerItem(Tiers.DIAMOND, props()));
|
||||
public static final RegistryObject<Item> NETHERITE_COMPRESSED_HAMMER = ITEMS.register("netherite_compressed_hammer", () -> new CompressedHammerItem(Tiers.NETHERITE, props()));
|
||||
|
||||
// Ore Chunks
|
||||
public static final RegistryObject<Item> IRON_ORE_CHUNK = registerSimpleItem("iron_ore_chunk");
|
||||
public static final RegistryObject<Item> 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());
|
||||
|
|
|
|||
|
|
@ -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<RecipeSerializer<FluidTransformationRecipe>> BARREL_FLUID_TRANSFORMATION = RECIPE_SERIALIZERS.register("barrel_fluid_transformation", FluidTransformationRecipe.Serializer::new);
|
||||
|
||||
public static final RegistryObject<RecipeSerializer<HammerRecipe>> HAMMER = RECIPE_SERIALIZERS.register("hammer", HammerRecipe.Serializer::new);
|
||||
public static final RegistryObject<RecipeSerializer<CompressedHammerRecipe>> COMPRESSED_HAMMER = RECIPE_SERIALIZERS.register("compressed_hammer", CompressedHammerRecipe.Serializer::new);
|
||||
public static final RegistryObject<RecipeSerializer<CrookRecipe>> CROOK = RECIPE_SERIALIZERS.register("crook", CrookRecipe.Serializer::new);
|
||||
public static final RegistryObject<RecipeSerializer<CrucibleHeatRecipe>> CRUCIBLE_HEAT_SOURCE = RECIPE_SERIALIZERS.register("crucible_heat_source", CrucibleHeatRecipe.Serializer::new);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<RecipeType<CrucibleRecipe>> WATER_CRUCIBLE = RECIPE_TYPES.register("water_crucible", () -> RecipeType.simple(ERecipeTypes.WATER_CRUCIBLE.getId()));
|
||||
|
||||
public static final RegistryObject<RecipeType<HammerRecipe>> HAMMER = RECIPE_TYPES.register("hammer", () -> RecipeType.simple(ERecipeTypes.HAMMER.getId()));
|
||||
public static final RegistryObject<RecipeType<CompressedHammerRecipe>> COMPRESSED_HAMMER = RECIPE_TYPES.register("compressed_hammer", () -> RecipeType.simple(ERecipeTypes.COMPRESSED_SIEVE.getId()));
|
||||
public static final RegistryObject<RecipeType<CrookRecipe>> CROOK = RECIPE_TYPES.register("crook", () -> RecipeType.simple(ERecipeTypes.CROOK.getId()));
|
||||
public static final RegistryObject<RecipeType<CrucibleHeatRecipe>> CRUCIBLE_HEAT_SOURCE = RECIPE_TYPES.register("crucible_heat_source", () -> RecipeType.simple(ERecipeTypes.CRUCIBLE_HEAT_SOURCE.getId()));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user