diff --git a/src/generated/resources/.cache/221483d9edeccdc82e726e39216c875f3fc356d3 b/src/generated/resources/.cache/221483d9edeccdc82e726e39216c875f3fc356d3 index fb9dc910..c3b1ce77 100644 --- a/src/generated/resources/.cache/221483d9edeccdc82e726e39216c875f3fc356d3 +++ b/src/generated/resources/.cache/221483d9edeccdc82e726e39216c875f3fc356d3 @@ -1,4 +1,4 @@ -// 1.20.1 2023-11-25T19:04:39.9873323 Tags for minecraft:item mod id exdeorum +// 1.20.1 2024-02-21T14:53:30.9830737 Tags for minecraft:item mod id exdeorum 6c72957356b1d59a27be736fa1da54a5a9795ef7 data/exdeorum/tags/items/barrels.json 5feb54ce68fa657af5ce696f75b8c7a6d04cc7a7 data/exdeorum/tags/items/crooks.json 74eefeb986d633d26ad42202c4a6b5e71463c425 data/exdeorum/tags/items/end_cake_materials.json @@ -6,4 +6,4 @@ be46bf2abe731d5ee5bd15ce72f222b2b9a49385 data/exdeorum/tags/items/hammers.json b90bd3c642e69b9e800c58a9f8f53e369652e6ba data/exdeorum/tags/items/pebbles.json 8e1b5ab26037123d3948e9ac9f50da1b7cd0a129 data/exdeorum/tags/items/sieve_meshes.json 0152da758e7665bf282f17f466599c7a009d9a15 data/exdeorum/tags/items/stone_barrels.json -da9e65a9ddbd1b6fa3ee55da4c0f8a041bb05dcd data/exdeorum/tags/items/wooden_barrels.json +8bde4a30abefaa373fa41813da07b6f79f32b874 data/exdeorum/tags/items/wooden_barrels.json diff --git a/src/generated/resources/.cache/711e6e4ef0ec2176e93c58a9656c8098f7158439 b/src/generated/resources/.cache/711e6e4ef0ec2176e93c58a9656c8098f7158439 index 285bfe73..f5aeca41 100644 --- a/src/generated/resources/.cache/711e6e4ef0ec2176e93c58a9656c8098f7158439 +++ b/src/generated/resources/.cache/711e6e4ef0ec2176e93c58a9656c8098f7158439 @@ -1,7 +1,7 @@ -// 1.20.1 2024-02-01T18:59:58.282244 Tags for minecraft:block mod id exdeorum +// 1.20.1 2024-02-21T14:54:39.5258231 Tags for minecraft:block mod id exdeorum 77dfab311d3714c77bcac2df0397d23d4707f03b data/exdeorum/tags/blocks/watering_can_tickable.json f6a9610ebae09549baf17e27200037cd17318055 data/minecraft/tags/blocks/leaves.json 6118dd1a976e5c95335fe0271c784eef3dac5bf5 data/minecraft/tags/blocks/mineable/axe.json f6a9610ebae09549baf17e27200037cd17318055 data/minecraft/tags/blocks/mineable/hoe.json -0cdcc5fc12eebe1808d6af184772b92e587e853f data/minecraft/tags/blocks/mineable/pickaxe.json +1fc4853812de00ec64713040f42af2e37b581955 data/minecraft/tags/blocks/mineable/pickaxe.json 0fc927ffe01dd23fd511dea057c7894680ae9807 data/minecraft/tags/blocks/mineable/shovel.json diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 12210294..5ac10da8 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -3,10 +3,10 @@ "exdeorum:porcelain_crucible", "exdeorum:unfired_porcelain_crucible", "exdeorum:crystallized_crucible", - "exdeorum:crystallized_sieve", "exdeorum:mechanical_sieve", "exdeorum:mechanical_hammer", "exdeorum:stone_barrel", - "exdeorum:crystallized_barrel" + "exdeorum:crystallized_barrel", + "exdeorum:crystallized_sieve" ] } \ No newline at end of file diff --git a/src/main/java/thedarkcolour/exdeorum/compat/CompatHelper.java b/src/main/java/thedarkcolour/exdeorum/compat/CompatHelper.java index 5d57075d..33740d5e 100644 --- a/src/main/java/thedarkcolour/exdeorum/compat/CompatHelper.java +++ b/src/main/java/thedarkcolour/exdeorum/compat/CompatHelper.java @@ -21,7 +21,7 @@ package thedarkcolour.exdeorum.compat; import com.google.common.collect.Lists; import net.minecraft.world.item.Item; import net.minecraftforge.fml.ModList; -import thedarkcolour.exdeorum.material.BarrelMaterial; +import thedarkcolour.exdeorum.material.DefaultMaterials; import thedarkcolour.exdeorum.registry.EItems; import java.util.ArrayList; @@ -30,7 +30,7 @@ import java.util.List; public class CompatHelper { public static List getAvailableBarrels(boolean registered) { List barrels = new ArrayList<>(); - for (var material : BarrelMaterial.REGISTERED_MATERIALS) { + for (var material : DefaultMaterials.BARRELS) { if (registered == ModList.get().isLoaded(material.requiredModId)) { barrels.add(material.getItem()); } @@ -38,49 +38,15 @@ public class CompatHelper { return barrels; } - public static List getAvailableSieves(boolean registered) { - List sieves = registered ? Lists.newArrayList( - EItems.OAK_SIEVE.get(), - EItems.SPRUCE_SIEVE.get(), - EItems.BIRCH_SIEVE.get(), - EItems.JUNGLE_SIEVE.get(), - EItems.ACACIA_SIEVE.get(), - EItems.DARK_OAK_SIEVE.get(), - EItems.MANGROVE_SIEVE.get(), - EItems.CHERRY_SIEVE.get(), - EItems.BAMBOO_SIEVE.get(), - EItems.CRIMSON_SIEVE.get(), - EItems.WARPED_SIEVE.get(), - EItems.MECHANICAL_SIEVE.get() - ) : new ArrayList<>(); - - if (ModList.get().isLoaded(ModIds.BIOMES_O_PLENTY) == registered) { - sieves.add(EItems.FIR_SIEVE.get()); - sieves.add(EItems.REDWOOD_SIEVE.get()); - sieves.add(EItems.MAHOGANY_SIEVE.get()); - sieves.add(EItems.JACARANDA_SIEVE.get()); - sieves.add(EItems.PALM_SIEVE.get()); - sieves.add(EItems.WILLOW_SIEVE.get()); - sieves.add(EItems.DEAD_SIEVE.get()); - sieves.add(EItems.MAGIC_SIEVE.get()); - sieves.add(EItems.UMBRAN_SIEVE.get()); - sieves.add(EItems.HELLBARK_SIEVE.get()); + public static List getAvailableSieves(boolean registered, boolean includeMechanical) { + List sieves = new ArrayList<>(); + for (var material : DefaultMaterials.SIEVES) { + if (registered == ModList.get().isLoaded(material.requiredModId)) { + sieves.add(material.getItem()); + } } - if (ModList.get().isLoaded(ModIds.ARS_NOUVEAU) == registered) { - sieves.add(EItems.ARCHWOOD_SIEVE.get()); - } - if (ModList.get().isLoaded(ModIds.AETHER) == registered) { - sieves.add(EItems.SKYROOT_SIEVE.get()); - } - if (ModList.get().isLoaded(ModIds.BLUE_SKIES) == registered) { - sieves.add(EItems.BLUEBRIGHT_SIEVE.get()); - sieves.add(EItems.STARLIT_SIEVE.get()); - sieves.add(EItems.FROSTBRIGHT_SIEVE.get()); - sieves.add(EItems.COMET_SIEVE.get()); - sieves.add(EItems.LUNAR_SIEVE.get()); - sieves.add(EItems.DUSK_SIEVE.get()); - sieves.add(EItems.MAPLE_SIEVE.get()); - sieves.add(EItems.CRYSTALLIZED_SIEVE.get()); + if (includeMechanical) { + sieves.add(EItems.MECHANICAL_SIEVE.get()); } return sieves; diff --git a/src/main/java/thedarkcolour/exdeorum/compat/jei/ExDeorumJeiPlugin.java b/src/main/java/thedarkcolour/exdeorum/compat/jei/ExDeorumJeiPlugin.java index 15735402..21ddbeb9 100644 --- a/src/main/java/thedarkcolour/exdeorum/compat/jei/ExDeorumJeiPlugin.java +++ b/src/main/java/thedarkcolour/exdeorum/compat/jei/ExDeorumJeiPlugin.java @@ -56,7 +56,6 @@ import thedarkcolour.exdeorum.recipe.barrel.BarrelFluidMixingRecipe; import thedarkcolour.exdeorum.recipe.barrel.BarrelMixingRecipe; import thedarkcolour.exdeorum.recipe.crucible.CrucibleRecipe; import thedarkcolour.exdeorum.recipe.hammer.HammerRecipe; -import thedarkcolour.exdeorum.registry.EBlocks; import thedarkcolour.exdeorum.registry.EFluids; import thedarkcolour.exdeorum.registry.EItems; import thedarkcolour.exdeorum.registry.ERecipeTypes; @@ -107,7 +106,7 @@ public class ExDeorumJeiPlugin implements IModPlugin { @Override public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { var barrels = CompatHelper.getAvailableBarrels(true); - var sieves = CompatHelper.getAvailableSieves(true); + var sieves = CompatHelper.getAvailableSieves(true, true); var lavaCrucibles = CompatHelper.getAvailableLavaCrucibles(true); var waterCrucibles = CompatHelper.getAvailableWaterCrucibles(true); @@ -144,7 +143,7 @@ public class ExDeorumJeiPlugin implements IModPlugin { @Override public void registerRecipes(IRecipeRegistration registration) { registration.addItemStackInfo(List.of(new ItemStack(EItems.INFESTED_LEAVES.get()), new ItemStack(EItems.SILK_WORM.get())), Component.translatable(TranslationKeys.SILK_WORM_JEI_INFO)); - registration.addItemStackInfo(List.of(new ItemStack(EBlocks.OAK_SIEVE.get()), new ItemStack(EBlocks.SPRUCE_SIEVE.get()), new ItemStack(EBlocks.BIRCH_SIEVE.get()), new ItemStack(EBlocks.JUNGLE_SIEVE.get()), new ItemStack(EBlocks.ACACIA_SIEVE.get()), new ItemStack(EBlocks.DARK_OAK_SIEVE.get()), new ItemStack(EBlocks.MANGROVE_SIEVE.get()), new ItemStack(EBlocks.CHERRY_SIEVE.get()), new ItemStack(EBlocks.BAMBOO_SIEVE.get()), new ItemStack(EBlocks.CRIMSON_SIEVE.get()), new ItemStack(EBlocks.WARPED_SIEVE.get())), Component.translatable(TranslationKeys.SIEVE_JEI_INFO)); + registration.addItemStackInfo(CompatHelper.getAvailableSieves(true, false).stream().map(ItemStack::new).toList(), Component.translatable(TranslationKeys.SIEVE_JEI_INFO)); registration.addItemStackInfo(List.of(new ItemStack(EItems.STRING_MESH.get()), new ItemStack(EItems.STRING_MESH.get()), new ItemStack(EItems.FLINT_MESH.get()), new ItemStack(EItems.IRON_MESH.get()), new ItemStack(EItems.GOLDEN_MESH.get()), new ItemStack(EItems.DIAMOND_MESH.get()), new ItemStack(EItems.NETHERITE_MESH.get())), Component.translatable(TranslationKeys.SIEVE_MESH_JEI_INFO)); registration.addItemStackInfo(List.of(WateringCanItem.getFull(EItems.WOODEN_WATERING_CAN), WateringCanItem.getFull(EItems.STONE_WATERING_CAN), WateringCanItem.getFull(EItems.IRON_WATERING_CAN), WateringCanItem.getFull(EItems.GOLDEN_WATERING_CAN), WateringCanItem.getFull(EItems.DIAMOND_WATERING_CAN), WateringCanItem.getFull(EItems.NETHERITE_WATERING_CAN)), Component.translatable(TranslationKeys.WATERING_CAN_JEI_INFO)); var witchWaterInfo = Component.translatable(TranslationKeys.WITCH_WATER_JEI_INFO); diff --git a/src/main/java/thedarkcolour/exdeorum/compat/jei/SieveCategory.java b/src/main/java/thedarkcolour/exdeorum/compat/jei/SieveCategory.java index bb2b5ce7..1790ad61 100644 --- a/src/main/java/thedarkcolour/exdeorum/compat/jei/SieveCategory.java +++ b/src/main/java/thedarkcolour/exdeorum/compat/jei/SieveCategory.java @@ -41,8 +41,8 @@ import net.minecraftforge.common.util.Lazy; import thedarkcolour.exdeorum.compat.GroupedSieveRecipe; import thedarkcolour.exdeorum.data.TranslationKeys; import thedarkcolour.exdeorum.loot.SummationGenerator; +import thedarkcolour.exdeorum.material.DefaultMaterials; import thedarkcolour.exdeorum.recipe.RecipeUtil; -import thedarkcolour.exdeorum.registry.EBlocks; class SieveCategory implements IRecipeCategory { private static final Component BY_HAND_ONLY_LABEL = Component.translatable(TranslationKeys.SIEVE_RECIPE_BY_HAND_ONLY).withStyle(ChatFormatting.RED); @@ -65,7 +65,7 @@ class SieveCategory implements IRecipeCategory { this.background = Lazy.of(() -> helper.createBlankDrawable(WIDTH, ROW_START + 18 * GroupedSieveRecipe.maxSieveRows)); this.slot = helper.getSlotDrawable(); this.row = helper.createDrawable(ExDeorumJeiPlugin.EX_DEORUM_JEI_TEXTURE, 0, 0, 162, 18); - this.icon = helper.createDrawableItemStack(new ItemStack(EBlocks.OAK_SIEVE.get())); + this.icon = helper.createDrawableItemStack(new ItemStack(DefaultMaterials.OAK_SIEVE.getItem())); this.title = Component.translatable(TranslationKeys.SIEVE_CATEGORY_TITLE); } diff --git a/src/main/java/thedarkcolour/exdeorum/compat/rei/ExDeorumReiPlugin.java b/src/main/java/thedarkcolour/exdeorum/compat/rei/ExDeorumReiPlugin.java index b4cc7c79..309bce81 100644 --- a/src/main/java/thedarkcolour/exdeorum/compat/rei/ExDeorumReiPlugin.java +++ b/src/main/java/thedarkcolour/exdeorum/compat/rei/ExDeorumReiPlugin.java @@ -38,7 +38,7 @@ public class ExDeorumReiPlugin implements REIClientPlugin { for (var barrel : CompatHelper.getAvailableBarrels(false)) { builder.add(EntryStack.of(VanillaEntryTypes.ITEM, new ItemStack(barrel))); } - for (var sieve : CompatHelper.getAvailableSieves(false)) { + for (var sieve : CompatHelper.getAvailableSieves(false, false)) { builder.add(EntryStack.of(VanillaEntryTypes.ITEM, new ItemStack(sieve))); } for (var crucible : CompatHelper.getAvailableLavaCrucibles(false)) { diff --git a/src/main/java/thedarkcolour/exdeorum/data/BlockModels.java b/src/main/java/thedarkcolour/exdeorum/data/BlockModels.java index ba13af9d..56075cb0 100644 --- a/src/main/java/thedarkcolour/exdeorum/data/BlockModels.java +++ b/src/main/java/thedarkcolour/exdeorum/data/BlockModels.java @@ -52,17 +52,17 @@ class BlockModels { barrel(models, DefaultMaterials.WARPED_BARREL.getBlock(), Blocks.WARPED_PLANKS); barrel(models, DefaultMaterials.STONE_BARREL.getBlock(), Blocks.STONE); - sieve(models, EBlocks.OAK_SIEVE.get(), Blocks.OAK_PLANKS); - sieve(models, EBlocks.SPRUCE_SIEVE.get(), Blocks.SPRUCE_PLANKS); - sieve(models, EBlocks.BIRCH_SIEVE.get(), Blocks.BIRCH_PLANKS); - sieve(models, EBlocks.JUNGLE_SIEVE.get(), Blocks.JUNGLE_PLANKS); - sieve(models, EBlocks.ACACIA_SIEVE.get(), Blocks.ACACIA_PLANKS); - sieve(models, EBlocks.DARK_OAK_SIEVE.get(), Blocks.DARK_OAK_PLANKS); - sieve(models, EBlocks.MANGROVE_SIEVE.get(), Blocks.MANGROVE_PLANKS); - sieve(models, EBlocks.CHERRY_SIEVE.get(), Blocks.CHERRY_PLANKS); - sieve(models, EBlocks.BAMBOO_SIEVE.get(), Blocks.BAMBOO_PLANKS); - sieve(models, EBlocks.CRIMSON_SIEVE.get(), Blocks.CRIMSON_PLANKS); - sieve(models, EBlocks.WARPED_SIEVE.get(), Blocks.WARPED_PLANKS); + sieve(models, DefaultMaterials.OAK_SIEVE.getBlock(), Blocks.OAK_PLANKS); + sieve(models, DefaultMaterials.SPRUCE_SIEVE.getBlock(), Blocks.SPRUCE_PLANKS); + sieve(models, DefaultMaterials.BIRCH_SIEVE.getBlock(), Blocks.BIRCH_PLANKS); + sieve(models, DefaultMaterials.JUNGLE_SIEVE.getBlock(), Blocks.JUNGLE_PLANKS); + sieve(models, DefaultMaterials.ACACIA_SIEVE.getBlock(), Blocks.ACACIA_PLANKS); + sieve(models, DefaultMaterials.DARK_OAK_SIEVE.getBlock(), Blocks.DARK_OAK_PLANKS); + sieve(models, DefaultMaterials.MANGROVE_SIEVE.getBlock(), Blocks.MANGROVE_PLANKS); + sieve(models, DefaultMaterials.CHERRY_SIEVE.getBlock(), Blocks.CHERRY_PLANKS); + sieve(models, DefaultMaterials.BAMBOO_SIEVE.getBlock(), Blocks.BAMBOO_PLANKS); + sieve(models, DefaultMaterials.CRIMSON_SIEVE.getBlock(), Blocks.CRIMSON_PLANKS); + sieve(models, DefaultMaterials.WARPED_SIEVE.getBlock(), Blocks.WARPED_PLANKS); // Lava Crucible crucible(models, EBlocks.UNFIRED_PORCELAIN_CRUCIBLE.get()); @@ -91,7 +91,7 @@ class BlockModels { private static void arsNouveauModels(MKBlockModelProvider models) { barrel(models, DefaultMaterials.ARCHWOOD_BARREL.getBlock(), ModCompatData.ARCHWOOD_PLANKS.get()); - sieve(models, EBlocks.ARCHWOOD_SIEVE.get(), ModCompatData.ARCHWOOD_PLANKS.get()); + sieve(models, DefaultMaterials.ARCHWOOD_SIEVE.getBlock(), ModCompatData.ARCHWOOD_PLANKS.get()); crucible(models, EBlocks.CASCADING_ARCHWOOD_CRUCIBLE.get(), ModCompatData.CASCADING_ARCHWOOD_LOG.get()); crucible(models, EBlocks.BLAZING_ARCHWOOD_CRUCIBLE.get(), ModCompatData.BLAZING_ARCHWOOD_LOG.get()); @@ -102,7 +102,7 @@ class BlockModels { private static void aetherModels(MKBlockModelProvider models) { barrel(models, DefaultMaterials.SKYROOT_BARREL.getBlock(), ModCompatData.SKYROOT_PLANKS.get(), "construction/"); - sieve(models, EBlocks.SKYROOT_SIEVE.get(), ModCompatData.SKYROOT_PLANKS.get(), "construction/"); + sieve(models, DefaultMaterials.SKYROOT_SIEVE.getBlock(), ModCompatData.SKYROOT_PLANKS.get(), "construction/"); crucible(models, EBlocks.SKYROOT_CRUCIBLE.get(), ModCompatData.SKYROOT_LOG.get(), "natural/", ""); crucible(models, EBlocks.GOLDEN_OAK_CRUCIBLE.get(), ModCompatData.GOLDEN_OAK_LOG.get(), "natural/", ""); @@ -121,14 +121,14 @@ class BlockModels { barrel(models, DefaultMaterials.MAPLE_BARREL.getBlock(), ModCompatData.MAPLE_PLANKS.get(), woodPrefix); barrel(models, DefaultMaterials.CRYSTALLIZED_BARREL.getBlock(), ModCompatData.CRYSTALLIZED_PLANKS.get(), woodPrefix).renderType("translucent"); - sieve(models, EBlocks.BLUEBRIGHT_SIEVE.get(), ModCompatData.BLUEBRIGHT_PLANKS.get(), woodPrefix); - sieve(models, EBlocks.STARLIT_SIEVE.get(), ModCompatData.STARLIT_PLANKS.get(), woodPrefix); - sieve(models, EBlocks.FROSTBRIGHT_SIEVE.get(), ModCompatData.FROSTBRIGHT_PLANKS.get(), woodPrefix); - sieve(models, EBlocks.COMET_SIEVE.get(), ModCompatData.COMET_PLANKS.get(), woodPrefix); - sieve(models, EBlocks.LUNAR_SIEVE.get(), ModCompatData.LUNAR_PLANKS.get(), woodPrefix); - sieve(models, EBlocks.DUSK_SIEVE.get(), ModCompatData.DUSK_PLANKS.get(), woodPrefix); - sieve(models, EBlocks.MAPLE_SIEVE.get(), ModCompatData.MAPLE_PLANKS.get(), woodPrefix); - sieve(models, EBlocks.CRYSTALLIZED_SIEVE.get(), ModCompatData.CRYSTALLIZED_PLANKS.get(), woodPrefix).renderType("translucent"); + sieve(models, DefaultMaterials.BLUEBRIGHT_SIEVE.getBlock(), ModCompatData.BLUEBRIGHT_PLANKS.get(), woodPrefix); + sieve(models, DefaultMaterials.STARLIT_SIEVE.getBlock(), ModCompatData.STARLIT_PLANKS.get(), woodPrefix); + sieve(models, DefaultMaterials.FROSTBRIGHT_SIEVE.getBlock(), ModCompatData.FROSTBRIGHT_PLANKS.get(), woodPrefix); + sieve(models, DefaultMaterials.COMET_SIEVE.getBlock(), ModCompatData.COMET_PLANKS.get(), woodPrefix); + sieve(models, DefaultMaterials.LUNAR_SIEVE.getBlock(), ModCompatData.LUNAR_PLANKS.get(), woodPrefix); + sieve(models, DefaultMaterials.DUSK_SIEVE.getBlock(), ModCompatData.DUSK_PLANKS.get(), woodPrefix); + sieve(models, DefaultMaterials.MAPLE_SIEVE.getBlock(), ModCompatData.MAPLE_PLANKS.get(), woodPrefix); + sieve(models, DefaultMaterials.CRYSTALLIZED_SIEVE.getBlock(), ModCompatData.CRYSTALLIZED_PLANKS.get(), woodPrefix).renderType("translucent"); crucible(models, EBlocks.BLUEBRIGHT_CRUCIBLE.get(), ModCompatData.BLUEBRIGHT_LOG.get(), woodPrefix, logSuffix); crucible(models, EBlocks.STARLIT_CRUCIBLE.get(), ModCompatData.STARLIT_LOG.get(), woodPrefix, logSuffix); @@ -152,16 +152,16 @@ class BlockModels { barrel(models, DefaultMaterials.UMBRAN_BARREL.getBlock(), ModCompatData.UMBRAN_PLANKS.get()); barrel(models, DefaultMaterials.HELLBARK_BARREL.getBlock(), ModCompatData.HELLBARK_PLANKS.get()); - sieve(models, EBlocks.FIR_SIEVE.get(), ModCompatData.FIR_PLANKS.get()); - sieve(models, EBlocks.REDWOOD_SIEVE.get(), ModCompatData.REDWOOD_PLANKS.get()); - sieve(models, EBlocks.MAHOGANY_SIEVE.get(), ModCompatData.MAHOGANY_PLANKS.get()); - sieve(models, EBlocks.JACARANDA_SIEVE.get(), ModCompatData.JACARANDA_PLANKS.get()); - sieve(models, EBlocks.PALM_SIEVE.get(), ModCompatData.PALM_PLANKS.get()); - sieve(models, EBlocks.WILLOW_SIEVE.get(), ModCompatData.WILLOW_PLANKS.get()); - sieve(models, EBlocks.DEAD_SIEVE.get(), ModCompatData.DEAD_PLANKS.get()); - sieve(models, EBlocks.MAGIC_SIEVE.get(), ModCompatData.MAGIC_PLANKS.get()); - sieve(models, EBlocks.UMBRAN_SIEVE.get(), ModCompatData.UMBRAN_PLANKS.get()); - sieve(models, EBlocks.HELLBARK_SIEVE.get(), ModCompatData.HELLBARK_PLANKS.get()); + sieve(models, DefaultMaterials.FIR_SIEVE.getBlock(), ModCompatData.FIR_PLANKS.get()); + sieve(models, DefaultMaterials.REDWOOD_SIEVE.getBlock(), ModCompatData.REDWOOD_PLANKS.get()); + sieve(models, DefaultMaterials.MAHOGANY_SIEVE.getBlock(), ModCompatData.MAHOGANY_PLANKS.get()); + sieve(models, DefaultMaterials.JACARANDA_SIEVE.getBlock(), ModCompatData.JACARANDA_PLANKS.get()); + sieve(models, DefaultMaterials.PALM_SIEVE.getBlock(), ModCompatData.PALM_PLANKS.get()); + sieve(models, DefaultMaterials.WILLOW_SIEVE.getBlock(), ModCompatData.WILLOW_PLANKS.get()); + sieve(models, DefaultMaterials.DEAD_SIEVE.getBlock(), ModCompatData.DEAD_PLANKS.get()); + sieve(models, DefaultMaterials.MAGIC_SIEVE.getBlock(), ModCompatData.MAGIC_PLANKS.get()); + sieve(models, DefaultMaterials.UMBRAN_SIEVE.getBlock(), ModCompatData.UMBRAN_PLANKS.get()); + sieve(models, DefaultMaterials.HELLBARK_SIEVE.getBlock(), ModCompatData.HELLBARK_PLANKS.get()); crucible(models, EBlocks.FIR_CRUCIBLE.get(), ModCompatData.FIR_LOG.get()); crucible(models, EBlocks.REDWOOD_CRUCIBLE.get(), ModCompatData.REDWOOD_LOG.get()); diff --git a/src/main/java/thedarkcolour/exdeorum/data/ModTags.java b/src/main/java/thedarkcolour/exdeorum/data/ModTags.java index 1c2d01ed..bc612b84 100644 --- a/src/main/java/thedarkcolour/exdeorum/data/ModTags.java +++ b/src/main/java/thedarkcolour/exdeorum/data/ModTags.java @@ -34,6 +34,7 @@ import net.minecraft.world.level.material.Fluid; import thedarkcolour.exdeorum.ExDeorum; import thedarkcolour.exdeorum.material.BarrelMaterial; import thedarkcolour.exdeorum.material.DefaultMaterials; +import thedarkcolour.exdeorum.material.SieveMaterial; import thedarkcolour.exdeorum.registry.EBlocks; import thedarkcolour.exdeorum.registry.EFluids; import thedarkcolour.exdeorum.registry.EItems; @@ -50,7 +51,7 @@ class ModTags { private static final List WOODEN_BARRELS = new ArrayList<>(); static { - for (var material : BarrelMaterial.REGISTERED_MATERIALS) { + for (var material : DefaultMaterials.BARRELS) { if (!STONE_MATERIALS.contains(material)) { WOODEN_BARRELS.add(material); } @@ -64,17 +65,10 @@ class ModTags { wateringCanTickable.addOptional(path); } - tags.tag(BlockTags.MINEABLE_WITH_AXE).add(WOODEN_BARRELS.stream().map(BarrelMaterial::getBlock).toArray(Block[]::new)).add( - // Vanilla sieves - EBlocks.OAK_SIEVE.get(), EBlocks.SPRUCE_SIEVE.get(), EBlocks.BIRCH_SIEVE.get(), EBlocks.JUNGLE_SIEVE.get(), EBlocks.ACACIA_SIEVE.get(), EBlocks.DARK_OAK_SIEVE.get(), EBlocks.MANGROVE_SIEVE.get(), EBlocks.CHERRY_SIEVE.get(), EBlocks.BAMBOO_SIEVE.get(), EBlocks.CRIMSON_SIEVE.get(), EBlocks.WARPED_SIEVE.get(), - // BOP sieves - EBlocks.FIR_SIEVE.get(), EBlocks.REDWOOD_SIEVE.get(), EBlocks.MAHOGANY_SIEVE.get(), EBlocks.JACARANDA_SIEVE.get(), EBlocks.PALM_SIEVE.get(), EBlocks.WILLOW_SIEVE.get(), EBlocks.DEAD_SIEVE.get(), EBlocks.MAGIC_SIEVE.get(), EBlocks.UMBRAN_SIEVE.get(), EBlocks.HELLBARK_SIEVE.get(), - // Ars Nouveau sieves - EBlocks.ARCHWOOD_SIEVE.get(), - // Aether sieves - EBlocks.SKYROOT_SIEVE.get(), - // Blue Skies sieves - EBlocks.BLUEBRIGHT_SIEVE.get(), EBlocks.STARLIT_SIEVE.get(), EBlocks.FROSTBRIGHT_SIEVE.get(), EBlocks.COMET_SIEVE.get(), EBlocks.LUNAR_SIEVE.get(), EBlocks.DUSK_SIEVE.get(), EBlocks.MAPLE_SIEVE.get(), + tags.tag(BlockTags.MINEABLE_WITH_AXE) + .add(WOODEN_BARRELS.stream().map(BarrelMaterial::getBlock).toArray(Block[]::new)) + .add(DefaultMaterials.SIEVES.stream().filter(material -> material != DefaultMaterials.CRYSTALLIZED_SIEVE).map(SieveMaterial::getBlock).toArray(Block[]::new)) + .add( // Vanilla crucibles EBlocks.WARPED_CRUCIBLE.get(), EBlocks.CRIMSON_CRUCIBLE.get(), EBlocks.OAK_CRUCIBLE.get(), EBlocks.SPRUCE_CRUCIBLE.get(), EBlocks.BIRCH_CRUCIBLE.get(), EBlocks.JUNGLE_CRUCIBLE.get(), EBlocks.ACACIA_CRUCIBLE.get(), EBlocks.DARK_OAK_CRUCIBLE.get(), EBlocks.MANGROVE_CRUCIBLE.get(), EBlocks.CHERRY_CRUCIBLE.get(), EBlocks.BAMBOO_CRUCIBLE.get(), // BOP crucibles @@ -87,8 +81,8 @@ class ModTags { EBlocks.BLUEBRIGHT_CRUCIBLE.get(), EBlocks.STARLIT_CRUCIBLE.get(), EBlocks.FROSTBRIGHT_CRUCIBLE.get(), EBlocks.COMET_CRUCIBLE.get(), EBlocks.LUNAR_CRUCIBLE.get(), EBlocks.DUSK_CRUCIBLE.get(), EBlocks.MAPLE_CRUCIBLE.get() ); tags.tag(BlockTags.MINEABLE_WITH_PICKAXE) - .add(EBlocks.PORCELAIN_CRUCIBLE, EBlocks.UNFIRED_PORCELAIN_CRUCIBLE, EBlocks.CRYSTALLIZED_CRUCIBLE, EBlocks.CRYSTALLIZED_SIEVE, EBlocks.MECHANICAL_SIEVE, EBlocks.MECHANICAL_HAMMER) - .add(DefaultMaterials.STONE_BARREL.getBlock(), DefaultMaterials.CRYSTALLIZED_BARREL.getBlock()); + .add(EBlocks.PORCELAIN_CRUCIBLE, EBlocks.UNFIRED_PORCELAIN_CRUCIBLE, EBlocks.CRYSTALLIZED_CRUCIBLE, EBlocks.MECHANICAL_SIEVE, EBlocks.MECHANICAL_HAMMER) + .add(DefaultMaterials.STONE_BARREL.getBlock(), DefaultMaterials.CRYSTALLIZED_BARREL.getBlock(), DefaultMaterials.CRYSTALLIZED_SIEVE.getBlock()); tags.tag(BlockTags.MINEABLE_WITH_SHOVEL).add(EBlocks.DUST, EBlocks.CRUSHED_NETHERRACK, EBlocks.CRUSHED_END_STONE, EBlocks.CRUSHED_DEEPSLATE, EBlocks.CRUSHED_BLACKSTONE); tags.tag(BlockTags.MINEABLE_WITH_HOE).add(EBlocks.INFESTED_LEAVES); tags.tag(BlockTags.LEAVES).add(EBlocks.INFESTED_LEAVES); diff --git a/src/main/java/thedarkcolour/exdeorum/data/recipe/Recipes.java b/src/main/java/thedarkcolour/exdeorum/data/recipe/Recipes.java index 97267fa7..8c251c48 100644 --- a/src/main/java/thedarkcolour/exdeorum/data/recipe/Recipes.java +++ b/src/main/java/thedarkcolour/exdeorum/data/recipe/Recipes.java @@ -214,38 +214,38 @@ public class Recipes { grid2x2TagResult(writer, recipes, EItemTags.ORES_BORON, ingredient(EItems.BORON_ORE_CHUNK)); // Sieves - sieve(recipes, EItems.OAK_SIEVE, Items.OAK_PLANKS, Items.OAK_SLAB); - sieve(recipes, EItems.SPRUCE_SIEVE, Items.SPRUCE_PLANKS, Items.SPRUCE_SLAB); - sieve(recipes, EItems.BIRCH_SIEVE, Items.BIRCH_PLANKS, Items.BIRCH_SLAB); - sieve(recipes, EItems.JUNGLE_SIEVE, Items.JUNGLE_PLANKS, Items.JUNGLE_SLAB); - sieve(recipes, EItems.ACACIA_SIEVE, Items.ACACIA_PLANKS, Items.ACACIA_SLAB); - sieve(recipes, EItems.DARK_OAK_SIEVE, Items.DARK_OAK_PLANKS, Items.DARK_OAK_SLAB); - sieve(recipes, EItems.MANGROVE_SIEVE, Items.MANGROVE_PLANKS, Items.MANGROVE_SLAB); - sieve(recipes, EItems.CHERRY_SIEVE, Items.CHERRY_PLANKS, Items.CHERRY_SLAB); - sieve(recipes, EItems.BAMBOO_SIEVE, Items.BAMBOO_PLANKS, Items.BAMBOO_SLAB); - sieve(recipes, EItems.CRIMSON_SIEVE, Items.CRIMSON_PLANKS, Items.CRIMSON_SLAB); - sieve(recipes, EItems.WARPED_SIEVE, Items.WARPED_PLANKS, Items.WARPED_SLAB); + sieve(recipes, DefaultMaterials.OAK_SIEVE.getItem(), Items.OAK_PLANKS, Items.OAK_SLAB); + sieve(recipes, DefaultMaterials.SPRUCE_SIEVE.getItem(), Items.SPRUCE_PLANKS, Items.SPRUCE_SLAB); + sieve(recipes, DefaultMaterials.BIRCH_SIEVE.getItem(), Items.BIRCH_PLANKS, Items.BIRCH_SLAB); + sieve(recipes, DefaultMaterials.JUNGLE_SIEVE.getItem(), Items.JUNGLE_PLANKS, Items.JUNGLE_SLAB); + sieve(recipes, DefaultMaterials.ACACIA_SIEVE.getItem(), Items.ACACIA_PLANKS, Items.ACACIA_SLAB); + sieve(recipes, DefaultMaterials.DARK_OAK_SIEVE.getItem(), Items.DARK_OAK_PLANKS, Items.DARK_OAK_SLAB); + sieve(recipes, DefaultMaterials.MANGROVE_SIEVE.getItem(), Items.MANGROVE_PLANKS, Items.MANGROVE_SLAB); + sieve(recipes, DefaultMaterials.CHERRY_SIEVE.getItem(), Items.CHERRY_PLANKS, Items.CHERRY_SLAB); + sieve(recipes, DefaultMaterials.BAMBOO_SIEVE.getItem(), Items.BAMBOO_PLANKS, Items.BAMBOO_SLAB); + sieve(recipes, DefaultMaterials.CRIMSON_SIEVE.getItem(), Items.CRIMSON_PLANKS, Items.CRIMSON_SLAB); + sieve(recipes, DefaultMaterials.WARPED_SIEVE.getItem(), Items.WARPED_PLANKS, Items.WARPED_SLAB); // Modded sieves - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.FIR_PLANKS_ITEM, ModCompatData.FIR_SLAB, EItems.FIR_SIEVE); - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.REDWOOD_PLANKS_ITEM, ModCompatData.REDWOOD_SLAB, EItems.REDWOOD_SIEVE); - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.MAHOGANY_PLANKS_ITEM, ModCompatData.MAHOGANY_SLAB, EItems.MAHOGANY_SIEVE); - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.JACARANDA_PLANKS_ITEM, ModCompatData.JACARANDA_SLAB, EItems.JACARANDA_SIEVE); - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.PALM_PLANKS_ITEM, ModCompatData.PALM_SLAB, EItems.PALM_SIEVE); - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.WILLOW_PLANKS_ITEM, ModCompatData.WILLOW_SLAB, EItems.WILLOW_SIEVE); - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.DEAD_PLANKS_ITEM, ModCompatData.DEAD_SLAB, EItems.DEAD_SIEVE); - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.MAGIC_PLANKS_ITEM, ModCompatData.MAGIC_SLAB, EItems.MAGIC_SIEVE); - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.UMBRAN_PLANKS_ITEM, ModCompatData.UMBRAN_SLAB, EItems.UMBRAN_SIEVE); - modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.HELLBARK_PLANKS_ITEM, ModCompatData.HELLBARK_SLAB, EItems.HELLBARK_SIEVE); - modSieve(recipes, ModIds.ARS_NOUVEAU, ModCompatData.ARCHWOOD_PLANKS_ITEM, ModCompatData.ARCHWOOD_SLAB, EItems.ARCHWOOD_SIEVE); - modSieve(recipes, ModIds.AETHER, ModCompatData.SKYROOT_PLANKS_ITEM, ModCompatData.SKYROOT_SLAB, EItems.SKYROOT_SIEVE); - modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.BLUEBRIGHT_PLANKS_ITEM, ModCompatData.BLUEBRIGHT_SLAB, EItems.BLUEBRIGHT_SIEVE); - modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.STARLIT_PLANKS_ITEM, ModCompatData.STARLIT_SLAB, EItems.STARLIT_SIEVE); - modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.FROSTBRIGHT_PLANKS_ITEM, ModCompatData.FROSTBRIGHT_SLAB, EItems.FROSTBRIGHT_SIEVE); - modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.COMET_PLANKS_ITEM, ModCompatData.COMET_SLAB, EItems.COMET_SIEVE); - modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.LUNAR_PLANKS_ITEM, ModCompatData.LUNAR_SLAB, EItems.LUNAR_SIEVE); - modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.DUSK_PLANKS_ITEM, ModCompatData.DUSK_SLAB, EItems.DUSK_SIEVE); - modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.MAPLE_PLANKS_ITEM, ModCompatData.MAPLE_SLAB, EItems.MAPLE_SIEVE); - modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.CRYSTALLIZED_PLANKS_ITEM, ModCompatData.CRYSTALLIZED_SLAB, EItems.CRYSTALLIZED_SIEVE); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.FIR_PLANKS_ITEM, ModCompatData.FIR_SLAB, DefaultMaterials.FIR_SIEVE.getItem()); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.REDWOOD_PLANKS_ITEM, ModCompatData.REDWOOD_SLAB, DefaultMaterials.REDWOOD_SIEVE.getItem()); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.MAHOGANY_PLANKS_ITEM, ModCompatData.MAHOGANY_SLAB, DefaultMaterials.MAHOGANY_SIEVE.getItem()); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.JACARANDA_PLANKS_ITEM, ModCompatData.JACARANDA_SLAB, DefaultMaterials.JACARANDA_SIEVE.getItem()); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.PALM_PLANKS_ITEM, ModCompatData.PALM_SLAB, DefaultMaterials.PALM_SIEVE.getItem()); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.WILLOW_PLANKS_ITEM, ModCompatData.WILLOW_SLAB, DefaultMaterials.WILLOW_SIEVE.getItem()); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.DEAD_PLANKS_ITEM, ModCompatData.DEAD_SLAB, DefaultMaterials.DEAD_SIEVE.getItem()); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.MAGIC_PLANKS_ITEM, ModCompatData.MAGIC_SLAB, DefaultMaterials.MAGIC_SIEVE.getItem()); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.UMBRAN_PLANKS_ITEM, ModCompatData.UMBRAN_SLAB, DefaultMaterials.UMBRAN_SIEVE.getItem()); + modSieve(recipes, ModIds.BIOMES_O_PLENTY, ModCompatData.HELLBARK_PLANKS_ITEM, ModCompatData.HELLBARK_SLAB, DefaultMaterials.HELLBARK_SIEVE.getItem()); + modSieve(recipes, ModIds.ARS_NOUVEAU, ModCompatData.ARCHWOOD_PLANKS_ITEM, ModCompatData.ARCHWOOD_SLAB, DefaultMaterials.ARCHWOOD_SIEVE.getItem()); + modSieve(recipes, ModIds.AETHER, ModCompatData.SKYROOT_PLANKS_ITEM, ModCompatData.SKYROOT_SLAB, DefaultMaterials.SKYROOT_SIEVE.getItem()); + modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.BLUEBRIGHT_PLANKS_ITEM, ModCompatData.BLUEBRIGHT_SLAB, DefaultMaterials.BLUEBRIGHT_SIEVE.getItem()); + modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.STARLIT_PLANKS_ITEM, ModCompatData.STARLIT_SLAB, DefaultMaterials.STARLIT_SIEVE.getItem()); + modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.FROSTBRIGHT_PLANKS_ITEM, ModCompatData.FROSTBRIGHT_SLAB, DefaultMaterials.FROSTBRIGHT_SIEVE.getItem()); + modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.COMET_PLANKS_ITEM, ModCompatData.COMET_SLAB, DefaultMaterials.COMET_SIEVE.getItem()); + modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.LUNAR_PLANKS_ITEM, ModCompatData.LUNAR_SLAB, DefaultMaterials.LUNAR_SIEVE.getItem()); + modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.DUSK_PLANKS_ITEM, ModCompatData.DUSK_SLAB, DefaultMaterials.DUSK_SIEVE.getItem()); + modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.MAPLE_PLANKS_ITEM, ModCompatData.MAPLE_SLAB, DefaultMaterials.MAPLE_SIEVE.getItem()); + modSieve(recipes, ModIds.BLUE_SKIES, ModCompatData.CRYSTALLIZED_PLANKS_ITEM, ModCompatData.CRYSTALLIZED_SLAB, DefaultMaterials.CRYSTALLIZED_SIEVE.getItem()); // Meshes recipes.grid3x3(EItems.STRING_MESH.get(), ingredient(Tags.Items.STRING)); @@ -327,8 +327,8 @@ public class Recipes { }); } - private static void modSieve(MKRecipeProvider recipes, String modid, RegistryObject planks, RegistryObject slab, RegistryObject result) { - recipes.conditional(result.getId().getPath(), List.of(modInstalled(modid)), writer1 -> { + private static void modSieve(MKRecipeProvider recipes, String modid, RegistryObject planks, RegistryObject slab, Item result) { + recipes.conditional(path(result), List.of(modInstalled(modid)), writer1 -> { sieve(recipes, result, planks.get(), slab.get()); }); } @@ -375,8 +375,8 @@ public class Recipes { }); } - private static void sieve(MKRecipeProvider recipes, Supplier result, Item planks, Item slab) { - recipes.shapedCrafting(RecipeCategory.MISC, result.get(), recipe -> { + private static void sieve(MKRecipeProvider recipes, Item result, Item planks, Item slab) { + recipes.shapedCrafting(RecipeCategory.MISC, result, recipe -> { recipe.define('O', planks); recipe.define('_', slab); recipe.define('I', Tags.Items.RODS_WOODEN); diff --git a/src/main/java/thedarkcolour/exdeorum/material/AbstractMaterial.java b/src/main/java/thedarkcolour/exdeorum/material/AbstractMaterial.java new file mode 100644 index 00000000..b0285fd6 --- /dev/null +++ b/src/main/java/thedarkcolour/exdeorum/material/AbstractMaterial.java @@ -0,0 +1,66 @@ +/* + * 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.material; + +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraftforge.registries.RegistryObject; + +public abstract class AbstractMaterial { + // The sound this block makes (a string corresponding to a field in SoundType or a JSON object with the five sound events used to create a sound type) + public final SoundType soundType; + // The hardness of the barrel when harvesting + public final float strength; + // Whether this barrel needs a special tool to be harvested (ex. stone barrel only drops if mined with pickaxe) + public final boolean needsCorrectTool; + // Numeric ID of map color (these can be found on Minecraft Wiki as well as in MapColor.java) + public final int mapColor; + // ID of mod that should be present + public final String requiredModId; + + RegistryObject block; + RegistryObject item; + + protected AbstractMaterial(SoundType soundType, float strength, boolean needsCorrectTool, int mapColor, String requiredModId) { + this.soundType = soundType; + this.strength = strength; + this.needsCorrectTool = needsCorrectTool; + this.mapColor = mapColor; + this.requiredModId = requiredModId; + } + + protected abstract Block createBlock(); + + protected BlockBehaviour.Properties props() { + var properties = BlockBehaviour.Properties.of().strength(this.strength).sound(this.soundType); + if (this.needsCorrectTool) properties.requiresCorrectToolForDrops(); + return properties; + } + + public Item getItem() { + return this.item.get(); + } + + public Block getBlock() { + return this.block.get(); + } +} diff --git a/src/main/java/thedarkcolour/exdeorum/material/BarrelMaterial.java b/src/main/java/thedarkcolour/exdeorum/material/BarrelMaterial.java index d0f1b18e..ee9de639 100644 --- a/src/main/java/thedarkcolour/exdeorum/material/BarrelMaterial.java +++ b/src/main/java/thedarkcolour/exdeorum/material/BarrelMaterial.java @@ -18,53 +18,21 @@ package thedarkcolour.exdeorum.material; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraftforge.data.loading.DatagenModLoader; import net.minecraftforge.registries.RegistryObject; import org.jetbrains.annotations.Nullable; -import thedarkcolour.exdeorum.ExDeorum; import thedarkcolour.exdeorum.block.BarrelBlock; -import thedarkcolour.exdeorum.blockentity.BarrelBlockEntity; -import thedarkcolour.exdeorum.client.CompostColors; -import thedarkcolour.exdeorum.registry.EBlocks; -import thedarkcolour.exdeorum.registry.EItems; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Set; -public final class BarrelMaterial { - // Use a linked hash map to maintain insertion order - public static final List REGISTERED_MATERIALS = new ArrayList<>(); +public final class BarrelMaterial extends AbstractMaterial { public static final Set TRANSPARENT_BARRELS = new HashSet<>(); - private static final Path CUSTOM_BARREL_MATERIAL_CONFIGS = Paths.get("config/exdeorum/barrel_materials"); - - // The sound this block makes (a string corresponding to a field in SoundType, or an unqualified field reference like me.mymod.block.Sounds.MODDED_SOUND_TYPE) - public final SoundType soundType; - // The hardness of the barrel when harvesting - public final float strength; - // Whether this barrel needs a special tool to be harvested (ex. stone barrel only drops if mined with pickaxe) - public final boolean needsCorrectTool; // Whether the barrel can hold hot fluids public final boolean fireproof; - // Numeric ID of map color (these can be found on Minecraft Wiki as well as in MapColor.java) - public final int mapColor; - // ID of mod that should be present - public final String requiredModId; // Whether fluids should be rendered with sides instead of just the top public final boolean transparent; @@ -72,176 +40,41 @@ public final class BarrelMaterial { private RegistryObject item; BarrelMaterial(SoundType soundType, float strength, boolean needsCorrectTool, boolean fireproof, int mapColor, String requiredModId, boolean transparent) { - this.soundType = soundType; - this.strength = strength; - this.needsCorrectTool = needsCorrectTool; + super(soundType, strength, needsCorrectTool, mapColor, requiredModId); + this.fireproof = fireproof; - this.mapColor = mapColor; - this.requiredModId = requiredModId; this.transparent = transparent; } - public static void findMaterials() { - if (DatagenModLoader.isRunningDataGen()) { - return; - } - if (CompostColors.createConfigFolder(CUSTOM_BARREL_MATERIAL_CONFIGS)) { - var materialsFolder = CUSTOM_BARREL_MATERIAL_CONFIGS.toFile(); - var children = materialsFolder.list(); - - if (children != null) { - for (var child : children) { - if (child.endsWith(".json")) { - Path path = CUSTOM_BARREL_MATERIAL_CONFIGS.resolve(child); - - try { - var json = JsonParser.parseString(Files.readString(path)); - var material = parseJsonMaterial((JsonObject) json, path); - - if (material != null) { - registerMaterial(child.substring(0, child.length() - 5), material); - } - } catch (IOException e) { - ExDeorum.LOGGER.error("Failed to read JSON custom barrel material at {}", path); - } - } - } - } else { - ExDeorum.LOGGER.error("Failed to read custom barrel materials folder {}: not a directory", CUSTOM_BARREL_MATERIAL_CONFIGS); - } - } + @Override + protected Block createBlock() { + var props = props(); + if (!this.fireproof) props.ignitedByLava(); + return new BarrelBlock(props); } - // Returns either the material or a list of errors that occurred while parsing @Nullable - private static BarrelMaterial parseJsonMaterial(JsonObject json, Path jsonPath) { - boolean error = false; - SoundType soundType = null; - float strength = 0; - boolean needsCorrectTool = false; - boolean fireproof = false; - int mapColor = 0; - String requiredModId = ExDeorum.ID; - boolean transparent = false; + public static BarrelMaterial readFromJson(MaterialParser parser) { + SoundType soundType = parser.getSoundType(); + float strength = parser.getStrength(); + int mapColor = parser.getMapColor(); + boolean needsCorrectTool = parser.getOptionalBoolean("needs_correct_tool"); + boolean fireproof = parser.getOptionalBoolean("fireproof"); + String requiredModId = parser.getRequiredModId(); + boolean transparent = parser.getOptionalBoolean("transparent"); - if (json.has("sound_type")) { - var soundTypeJson = json.get("sound_type"); - - if (soundTypeJson.isJsonPrimitive()) { - String soundTypeString = soundTypeJson.getAsString(); - soundType = SoundTypeResolver.VANILLA_SOUND_TYPES.get(soundTypeString); - - if (soundType == null) { - ExDeorum.LOGGER.error("Unknown sound type \"{}\" for barrel material {}", soundTypeString, jsonPath); - error = true; - } - } else if (soundTypeJson instanceof JsonObject soundTypeObj) { - // todo let users define sound types with registry names - } else { - ExDeorum.LOGGER.error("Unable to parse sound type for barrel material {}", jsonPath); - error = true; - } - } else { - ExDeorum.LOGGER.error("Missing sound_type property for barrel material {}", jsonPath); - error = true; - } - if (json.has("strength")) { - var strengthJson = json.get("strength"); - - if (strengthJson.isJsonPrimitive()) { - try { - strength = strengthJson.getAsFloat(); - } catch (NumberFormatException e) { - ExDeorum.LOGGER.error("Failed to parse strength property for barrel material {} with value {}", jsonPath, strengthJson.getAsString()); - error = true; - } - } else { - ExDeorum.LOGGER.error("Failed to parse strength property for barrel material {}: not a number", jsonPath); - error = true; - } - } else { - ExDeorum.LOGGER.error("Missing strength property for barrel material {}", jsonPath); - error = true; - } - - if (json.has("map_color")) { - if (json.get("map_color") instanceof JsonPrimitive prim) { - mapColor = prim.getAsInt(); - if (64 <= mapColor || mapColor < 0) { - ExDeorum.LOGGER.error("Failed to parse map_color property for barrel material {}: value must be in [0,64), found {}", jsonPath, mapColor); - error = true; - } - } else { - ExDeorum.LOGGER.error("Failed to parse map_color property for barrel material {}: not a number", jsonPath); - error = true; - } - } else { - ExDeorum.LOGGER.error("Missing map_color property for barrel material {}", jsonPath); - error = true; - } - - if (json.get("needs_correct_tool") instanceof JsonPrimitive prim && prim.isBoolean()) { - needsCorrectTool = prim.getAsBoolean(); - } - if (json.get("fireproof") instanceof JsonPrimitive prim && prim.isBoolean()) { - fireproof = prim.getAsBoolean(); - } - if (json.get("required_mod_id") instanceof JsonPrimitive prim && prim.isString()) { - requiredModId = prim.getAsString(); - } - if (json.get("transparent") instanceof JsonPrimitive prim && prim.isBoolean()) { - transparent = prim.getAsBoolean(); - } - - if (error) { + if (parser.error) { return null; } else { return new BarrelMaterial(soundType, strength, needsCorrectTool, fireproof, mapColor, requiredModId, transparent); } } - public static void registerMaterial(String name, BarrelMaterial material) { - var id = name + "_barrel"; - ExDeorum.LOGGER.info("Added barrel \"{}\" for barrel material {}: {}", id, name + ".json", material); - - if (material.block != null) { - throw new IllegalStateException("Tried to set block on material" + name + ", but block was already set!"); - } - - material.block = EBlocks.BLOCKS.register(id, () -> { - BlockBehaviour.Properties props = BlockBehaviour.Properties.of().strength(material.strength).sound(material.soundType); - if (!material.fireproof) props.ignitedByLava(); - if (material.needsCorrectTool) props.requiresCorrectToolForDrops(); - return new BarrelBlock(props); - }); - material.item = EItems.registerItemBlock(material.block); - REGISTERED_MATERIALS.add(material); - } - - public static BlockEntityType createBlockEntityType() { - HashSet validBlocks = new HashSet<>(); - - for (var material : REGISTERED_MATERIALS) { - validBlocks.add(material.block.get()); - } - - return new BlockEntityType<>(BarrelBlockEntity::new, validBlocks, null); - } - public static void loadTransparentBlocks() { - for (var material : REGISTERED_MATERIALS) { + for (var material : DefaultMaterials.BARRELS) { if (material.transparent) { TRANSPARENT_BARRELS.add(material.getBlock()); } } } - - // Does not check if the mod is registered - public Item getItem() { - return this.item.get(); - } - - public Block getBlock() { - return this.block.get(); - } } diff --git a/src/main/java/thedarkcolour/exdeorum/material/DefaultMaterials.java b/src/main/java/thedarkcolour/exdeorum/material/DefaultMaterials.java index 372f2a48..62169dc5 100644 --- a/src/main/java/thedarkcolour/exdeorum/material/DefaultMaterials.java +++ b/src/main/java/thedarkcolour/exdeorum/material/DefaultMaterials.java @@ -25,6 +25,9 @@ import thedarkcolour.exdeorum.compat.ModIds; @SuppressWarnings("unused") public class DefaultMaterials { + public static final MaterialRegistry BARRELS = new MaterialRegistry<>("barrel"); + public static final MaterialRegistry SIEVES = new MaterialRegistry<>("sieve"); + // Ex Deorum public static final BarrelMaterial OAK_BARREL = addDefaultWoodBarrel("oak", SoundType.WOOD, false, MapColor.WOOD, ExDeorum.ID); public static final BarrelMaterial SPRUCE_BARREL = addDefaultWoodBarrel("spruce", SoundType.WOOD, false, MapColor.PODZOL, ExDeorum.ID); @@ -33,8 +36,8 @@ public class DefaultMaterials { public static final BarrelMaterial ACACIA_BARREL = addDefaultWoodBarrel("acacia", SoundType.WOOD, false, MapColor.COLOR_ORANGE, ExDeorum.ID); public static final BarrelMaterial DARK_OAK_BARREL = addDefaultWoodBarrel("dark_oak", SoundType.WOOD, false, MapColor.COLOR_BROWN, ExDeorum.ID); public static final BarrelMaterial MANGROVE_BARREL = addDefaultWoodBarrel("mangrove", SoundType.WOOD, false, MapColor.COLOR_RED, ExDeorum.ID); - public static final BarrelMaterial CHERRY_BARREL = addDefaultWoodBarrel("cherry", SoundType.WOOD, false, MapColor.TERRACOTTA_WHITE, ExDeorum.ID); - public static final BarrelMaterial BAMBOO_BARREL = addDefaultWoodBarrel("bamboo", SoundType.BAMBOO, false, MapColor.COLOR_YELLOW, ExDeorum.ID); + public static final BarrelMaterial CHERRY_BARREL = addDefaultWoodBarrel("cherry", SoundType.CHERRY_WOOD, false, MapColor.TERRACOTTA_WHITE, ExDeorum.ID); + public static final BarrelMaterial BAMBOO_BARREL = addDefaultWoodBarrel("bamboo", SoundType.BAMBOO_WOOD, false, MapColor.COLOR_YELLOW, ExDeorum.ID); public static final BarrelMaterial CRIMSON_BARREL = addDefaultWoodBarrel("crimson", SoundType.NETHER_WOOD, true, MapColor.CRIMSON_STEM, ExDeorum.ID); public static final BarrelMaterial WARPED_BARREL = addDefaultWoodBarrel("warped", SoundType.NETHER_WOOD, true, MapColor.WARPED_STEM, ExDeorum.ID); public static final BarrelMaterial STONE_BARREL = addDefaultBarrel("stone", SoundType.STONE, 4.0f, true, true, MapColor.STONE, ExDeorum.ID, false); @@ -63,18 +66,66 @@ public class DefaultMaterials { public static final BarrelMaterial MAPLE_BARREL = addDefaultWoodBarrel("maple", SoundType.WOOD, false, MapColor.WOOD, ModIds.BLUE_SKIES); public static final BarrelMaterial CRYSTALLIZED_BARREL = addDefaultBarrel("crystallized", SoundType.GLASS, 4.0f, true, true, MapColor.TERRACOTTA_WHITE, ModIds.BLUE_SKIES, true); - static BarrelMaterial addDefaultWoodBarrel(String name, SoundType soundType, boolean fireproof, MapColor color, String requiredModId) { + // Ex Deorum + public static final SieveMaterial OAK_SIEVE = addDefaultSieve("oak", SoundType.WOOD, ExDeorum.ID); + public static final SieveMaterial SPRUCE_SIEVE = addDefaultSieve("spruce", SoundType.WOOD, ExDeorum.ID); + public static final SieveMaterial BIRCH_SIEVE = addDefaultSieve("birch", SoundType.WOOD, ExDeorum.ID); + public static final SieveMaterial JUNGLE_SIEVE = addDefaultSieve("jungle", SoundType.WOOD, ExDeorum.ID); + public static final SieveMaterial ACACIA_SIEVE = addDefaultSieve("acacia", SoundType.WOOD, ExDeorum.ID); + public static final SieveMaterial DARK_OAK_SIEVE = addDefaultSieve("dark_oak", SoundType.WOOD, ExDeorum.ID); + public static final SieveMaterial MANGROVE_SIEVE = addDefaultSieve("mangrove", SoundType.WOOD, ExDeorum.ID); + public static final SieveMaterial CHERRY_SIEVE = addDefaultSieve("cherry", SoundType.CHERRY_WOOD, ExDeorum.ID); + public static final SieveMaterial BAMBOO_SIEVE = addDefaultSieve("bamboo", SoundType.BAMBOO_WOOD, ExDeorum.ID); + public static final SieveMaterial CRIMSON_SIEVE = addDefaultSieve("crimson", SoundType.NETHER_WOOD, ExDeorum.ID); + public static final SieveMaterial WARPED_SIEVE = addDefaultSieve("warped", SoundType.NETHER_WOOD, ExDeorum.ID); + // Biomes O' Plenty + public static final SieveMaterial FIR_SIEVE = addDefaultSieve("fir", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + public static final SieveMaterial REDWOOD_SIEVE = addDefaultSieve("redwood", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + public static final SieveMaterial MAHOGANY_SIEVE = addDefaultSieve("mahogany", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + public static final SieveMaterial JACARANDA_SIEVE = addDefaultSieve("jacaranda", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + public static final SieveMaterial PALM_SIEVE = addDefaultSieve("palm", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + public static final SieveMaterial WILLOW_SIEVE = addDefaultSieve("willow", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + public static final SieveMaterial DEAD_SIEVE = addDefaultSieve("dead", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + public static final SieveMaterial MAGIC_SIEVE = addDefaultSieve("magic", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + public static final SieveMaterial UMBRAN_SIEVE = addDefaultSieve("umbran", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + public static final SieveMaterial HELLBARK_SIEVE = addDefaultSieve("hellbark", SoundType.WOOD, ModIds.BIOMES_O_PLENTY); + // Ars Nouveau + public static final SieveMaterial ARCHWOOD_SIEVE = addDefaultSieve("archwood", SoundType.WOOD, ModIds.ARS_NOUVEAU); + // Aether + public static final SieveMaterial SKYROOT_SIEVE = addDefaultSieve("skyroot", SoundType.WOOD, ModIds.AETHER); + // Blue Skies + public static final SieveMaterial BLUEBRIGHT_SIEVE = addDefaultSieve("bluebright", SoundType.WOOD, ModIds.BLUE_SKIES); + public static final SieveMaterial STARLIT_SIEVE = addDefaultSieve("starlit", SoundType.WOOD, ModIds.BLUE_SKIES); + public static final SieveMaterial FROSTBRIGHT_SIEVE = addDefaultSieve("frostbright", SoundType.WOOD, ModIds.BLUE_SKIES); + public static final SieveMaterial COMET_SIEVE = addDefaultSieve("comet", SoundType.WOOD, ModIds.BLUE_SKIES); + public static final SieveMaterial LUNAR_SIEVE = addDefaultSieve("lunar", SoundType.WOOD, ModIds.BLUE_SKIES); + public static final SieveMaterial DUSK_SIEVE = addDefaultSieve("dusk", SoundType.WOOD, ModIds.BLUE_SKIES); + public static final SieveMaterial MAPLE_SIEVE = addDefaultSieve("maple", SoundType.WOOD, ModIds.BLUE_SKIES); + public static final SieveMaterial CRYSTALLIZED_SIEVE = addDefaultSieve("crystallized", SoundType.GLASS, true, ModIds.BLUE_SKIES); + + private static BarrelMaterial addDefaultWoodBarrel(String name, SoundType soundType, boolean fireproof, MapColor color, String requiredModId) { return addDefaultBarrel(name, soundType, 2.0f, false, fireproof, color, requiredModId, false); } - static BarrelMaterial addDefaultBarrel(String name, SoundType soundType, float strength, boolean needsCorrectTool, boolean fireproof, MapColor color, String requiredModId, boolean transparent) { + private static BarrelMaterial addDefaultBarrel(String name, SoundType soundType, float strength, boolean needsCorrectTool, boolean fireproof, MapColor color, String requiredModId, boolean transparent) { var material = new BarrelMaterial(soundType, strength, needsCorrectTool, fireproof, color.id, requiredModId, transparent); - BarrelMaterial.registerMaterial(name, material); + BARRELS.register(name, material); + return material; + } + + private static SieveMaterial addDefaultSieve(String name, SoundType soundType, String requiredModId) { + return addDefaultSieve(name, soundType, false, requiredModId); + } + + private static SieveMaterial addDefaultSieve(String name, SoundType soundType, boolean needsCorrectTool, String requiredModID) { + var material = new SieveMaterial(soundType, 2.0f, needsCorrectTool, requiredModID); + SIEVES.register(name, material); return material; } // This call initializes the DefaultMaterials fields as well as searching for user-defined ones in the appropriate places public static void registerMaterials() { - BarrelMaterial.findMaterials(); + BARRELS.search(BarrelMaterial::readFromJson); + SIEVES.search(SieveMaterial::readFromJson); } } diff --git a/src/main/java/thedarkcolour/exdeorum/material/MaterialParser.java b/src/main/java/thedarkcolour/exdeorum/material/MaterialParser.java new file mode 100644 index 00000000..d13fa9ba --- /dev/null +++ b/src/main/java/thedarkcolour/exdeorum/material/MaterialParser.java @@ -0,0 +1,142 @@ +/* + * 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.material; + +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.SoundType; +import net.minecraftforge.common.util.ForgeSoundType; +import net.minecraftforge.registries.RegistryObject; +import org.jetbrains.annotations.Nullable; +import thedarkcolour.exdeorum.ExDeorum; + +import java.nio.file.Path; + +public class MaterialParser { + private final JsonObject json; + private final Path jsonPath; + @Nullable + private final MaterialRegistry registry; + boolean error; + + public MaterialParser(JsonObject json, Path jsonPath, @Nullable MaterialRegistry registry) { + this.json = json; + this.jsonPath = jsonPath; + this.registry = registry; + } + + public SoundType getSoundType() { + if (this.json.has("sound_type")) { + var soundTypeJson = this.json.get("sound_type"); + + if (soundTypeJson.isJsonPrimitive()) { + String soundTypeString = soundTypeJson.getAsString(); + var soundType = SoundTypeResolver.VANILLA_SOUND_TYPES.get(soundTypeString); + + if (soundType == null) { + ExDeorum.LOGGER.error("Unknown sound type \"{}\" for material {}", soundTypeString, this.jsonPath); + this.error = true; + } else { + return soundType; + } + } else if (soundTypeJson instanceof JsonObject soundTypeObj) { + if (soundTypeObj.has("break_sound") && soundTypeObj.has("step_sound") && soundTypeObj.has("place_sound") && soundTypeObj.has("hit_sound") && soundTypeObj.has("fall_sound")) { + return new ForgeSoundType(1.0f, 1.0f, + RegistryObject.create(new ResourceLocation(soundTypeObj.get("break_sound").getAsString()), Registries.SOUND_EVENT, ExDeorum.ID), + RegistryObject.create(new ResourceLocation(soundTypeObj.get("step_sound").getAsString()), Registries.SOUND_EVENT, ExDeorum.ID), + RegistryObject.create(new ResourceLocation(soundTypeObj.get("place_sound").getAsString()), Registries.SOUND_EVENT, ExDeorum.ID), + RegistryObject.create(new ResourceLocation(soundTypeObj.get("hit_sound").getAsString()), Registries.SOUND_EVENT, ExDeorum.ID), + RegistryObject.create(new ResourceLocation(soundTypeObj.get("fall_sound").getAsString()), Registries.SOUND_EVENT, ExDeorum.ID) + ); + } + } else { + ExDeorum.LOGGER.error("Unable to parse sound type for material {}", this.jsonPath); + this.error = true; + } + } else { + ExDeorum.LOGGER.error("Missing sound_type property for material {}", this.jsonPath); + this.error = true; + } + + return SoundType.WOOD; + } + + public float getStrength() { + if (this.json.has("strength")) { + var strengthJson = this.json.get("strength"); + + if (strengthJson.isJsonPrimitive()) { + try { + return strengthJson.getAsFloat(); + } catch (NumberFormatException e) { + ExDeorum.LOGGER.error("Failed to parse strength property for material {} with value {}", this.jsonPath, strengthJson.getAsString()); + this.error = true; + } + } else { + ExDeorum.LOGGER.error("Failed to parse strength property for material {}: not a number", this.jsonPath); + this.error = true; + } + } else { + if (this.registry == DefaultMaterials.SIEVES) { + return 2f; + } else { + ExDeorum.LOGGER.error("Missing strength property for material {}", this.jsonPath); + this.error = true; + } + } + + return 0f; + } + + public int getMapColor() { + if (this.json.has("map_color")) { + if (this.json.get("map_color") instanceof JsonPrimitive prim) { + var mapColor = prim.getAsInt(); + if (64 <= mapColor || mapColor < 0) { + ExDeorum.LOGGER.error("Failed to parse map_color property for material {}: value must be in [0,64), found {}", this.jsonPath, mapColor); + this.error = true; + } else { + return mapColor; + } + } else { + ExDeorum.LOGGER.error("Failed to parse map_color property for material {}: not a number", this.jsonPath); + this.error = true; + } + } else { + ExDeorum.LOGGER.error("Missing map_color property for material {}", this.jsonPath); + this.error = true; + } + + return 0; + } + + public boolean getOptionalBoolean(String key) { + return this.json.get(key) instanceof JsonPrimitive prim && prim.isBoolean() && prim.getAsBoolean(); + } + + public String getRequiredModId() { + if (this.json.get("required_mod_id") instanceof JsonPrimitive prim && prim.isString()) { + return prim.getAsString(); + } else { + return ExDeorum.ID; + } + } +} diff --git a/src/main/java/thedarkcolour/exdeorum/material/MaterialRegistry.java b/src/main/java/thedarkcolour/exdeorum/material/MaterialRegistry.java new file mode 100644 index 00000000..1901a252 --- /dev/null +++ b/src/main/java/thedarkcolour/exdeorum/material/MaterialRegistry.java @@ -0,0 +1,118 @@ +/* + * 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.material; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraftforge.data.loading.DatagenModLoader; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import thedarkcolour.exdeorum.ExDeorum; +import thedarkcolour.exdeorum.client.CompostColors; +import thedarkcolour.exdeorum.registry.EBlocks; +import thedarkcolour.exdeorum.registry.EItems; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Stream; + +public class MaterialRegistry implements Iterable { + private final List values = new ArrayList<>(); + private final String suffix; + + // Suffix should NOT start with an underscore + public MaterialRegistry(String suffix) { + this.suffix = suffix; + + Preconditions.checkArgument(!suffix.startsWith("_")); + } + + public void search(Function materialRegistrar) { + var configPath = Paths.get("config/exdeorum/" + this.suffix + "_materials"); + + if (!DatagenModLoader.isRunningDataGen()) { + if (CompostColors.createConfigFolder(configPath)) { + var materialsFolder = configPath.toFile(); + var children = materialsFolder.list(); + + if (children != null) { + for (var child : children) { + if (child.endsWith(".json")) { + Path jsonPath = configPath.resolve(child); + + try { + var json = (JsonObject) JsonParser.parseString(Files.readString(jsonPath)); + var material = materialRegistrar.apply(new MaterialParser(json, jsonPath, this)); + + if (material != null) { + register(child.substring(0, child.length() - 5), material); + } + } catch (IOException e) { + ExDeorum.LOGGER.error("Failed to read JSON custom material at {}", jsonPath); + } + } + } + } else { + ExDeorum.LOGGER.error("Failed to read JSON custom materials at {}: not a directory", configPath); + } + } + } + } + + public void register(String name, M material) { + var id = name + "_" + this.suffix; + ExDeorum.LOGGER.info("Registered \"{}\" for {} material {}.json", id, this.suffix, name); + + if (material.block != null) { + throw new IllegalStateException(this.suffix + " material with name " + name + " already registered: duplicate material?"); + } + + material.block = EBlocks.BLOCKS.register(id, material::createBlock); + material.item = EItems.registerItemBlock(material.block); + this.values.add(material); + } + + public BlockEntityType createBlockEntityType(BlockEntityType.BlockEntitySupplier factory) { + ImmutableSet.Builder validBlocks = ImmutableSet.builder(); + + for (var material : this.values) { + validBlocks.add(material.block.get()); + } + + return new BlockEntityType<>(factory, validBlocks.build(), null); + } + + @Override + public Iterator iterator() { + return this.values.iterator(); + } + + public Stream stream() { + return this.values.stream(); + } +} diff --git a/src/main/java/thedarkcolour/exdeorum/material/SieveMaterial.java b/src/main/java/thedarkcolour/exdeorum/material/SieveMaterial.java new file mode 100644 index 00000000..8413529a --- /dev/null +++ b/src/main/java/thedarkcolour/exdeorum/material/SieveMaterial.java @@ -0,0 +1,49 @@ +/* + * 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.material; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import org.jetbrains.annotations.Nullable; +import thedarkcolour.exdeorum.block.SieveBlock; + +public class SieveMaterial extends AbstractMaterial { + public SieveMaterial(SoundType soundType, float strength, boolean needsCorrectTool, String requiredModId) { + super(soundType, strength, needsCorrectTool, 0, requiredModId); + } + + @Override + protected Block createBlock() { + return new SieveBlock(props().noOcclusion()); + } + + @Nullable + public static SieveMaterial readFromJson(MaterialParser parser) { + SoundType soundType = parser.getSoundType(); + float strength = parser.getStrength(); + boolean needsCorrectTool = parser.getOptionalBoolean("needs_correct_tool"); + String requiredModId = parser.getRequiredModId(); + + if (parser.error) { + return null; + } else { + return new SieveMaterial(soundType, strength, needsCorrectTool, requiredModId); + } + } +} diff --git a/src/main/java/thedarkcolour/exdeorum/registry/EBlockEntities.java b/src/main/java/thedarkcolour/exdeorum/registry/EBlockEntities.java index fd2053b4..e54fa99a 100644 --- a/src/main/java/thedarkcolour/exdeorum/registry/EBlockEntities.java +++ b/src/main/java/thedarkcolour/exdeorum/registry/EBlockEntities.java @@ -23,14 +23,8 @@ import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; import thedarkcolour.exdeorum.ExDeorum; -import thedarkcolour.exdeorum.blockentity.BarrelBlockEntity; -import thedarkcolour.exdeorum.blockentity.InfestedLeavesBlockEntity; -import thedarkcolour.exdeorum.blockentity.LavaCrucibleBlockEntity; -import thedarkcolour.exdeorum.blockentity.MechanicalHammerBlockEntity; -import thedarkcolour.exdeorum.blockentity.MechanicalSieveBlockEntity; -import thedarkcolour.exdeorum.blockentity.SieveBlockEntity; -import thedarkcolour.exdeorum.blockentity.WaterCrucibleBlockEntity; -import thedarkcolour.exdeorum.material.BarrelMaterial; +import thedarkcolour.exdeorum.blockentity.*; +import thedarkcolour.exdeorum.material.DefaultMaterials; public class EBlockEntities { public static final DeferredRegister> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, ExDeorum.ID); @@ -82,44 +76,8 @@ public class EBlockEntities { EBlocks.DUSK_CRUCIBLE.get(), EBlocks.MAPLE_CRUCIBLE.get() ).build(null)); - public static final RegistryObject> BARREL = BLOCK_ENTITIES.register("barrel", BarrelMaterial::createBlockEntityType); - public static final RegistryObject> SIEVE = BLOCK_ENTITIES.register("sieve", () -> BlockEntityType.Builder.of(SieveBlockEntity::new, - EBlocks.OAK_SIEVE.get(), - EBlocks.SPRUCE_SIEVE.get(), - EBlocks.BIRCH_SIEVE.get(), - EBlocks.JUNGLE_SIEVE.get(), - EBlocks.ACACIA_SIEVE.get(), - EBlocks.DARK_OAK_SIEVE.get(), - EBlocks.MANGROVE_SIEVE.get(), - EBlocks.CHERRY_SIEVE.get(), - EBlocks.BAMBOO_SIEVE.get(), - EBlocks.CRIMSON_SIEVE.get(), - EBlocks.WARPED_SIEVE.get(), - // BOP - EBlocks.FIR_SIEVE.get(), - EBlocks.REDWOOD_SIEVE.get(), - EBlocks.MAHOGANY_SIEVE.get(), - EBlocks.JACARANDA_SIEVE.get(), - EBlocks.PALM_SIEVE.get(), - EBlocks.WILLOW_SIEVE.get(), - EBlocks.DEAD_SIEVE.get(), - EBlocks.MAGIC_SIEVE.get(), - EBlocks.UMBRAN_SIEVE.get(), - EBlocks.HELLBARK_SIEVE.get(), - // Ars Nouveau - EBlocks.ARCHWOOD_SIEVE.get(), - // Aether - EBlocks.SKYROOT_SIEVE.get(), - // Blue Skies - EBlocks.BLUEBRIGHT_SIEVE.get(), - EBlocks.STARLIT_SIEVE.get(), - EBlocks.FROSTBRIGHT_SIEVE.get(), - EBlocks.COMET_SIEVE.get(), - EBlocks.LUNAR_SIEVE.get(), - EBlocks.DUSK_SIEVE.get(), - EBlocks.MAPLE_SIEVE.get(), - EBlocks.CRYSTALLIZED_SIEVE.get() - ).build(null)); + public static final RegistryObject> BARREL = BLOCK_ENTITIES.register("barrel", () -> DefaultMaterials.BARRELS.createBlockEntityType(BarrelBlockEntity::new)); + public static final RegistryObject> SIEVE = BLOCK_ENTITIES.register("sieve", () -> DefaultMaterials.SIEVES.createBlockEntityType(SieveBlockEntity::new)); public static final RegistryObject> MECHANICAL_SIEVE = BLOCK_ENTITIES.register("mechanical_sieve", () -> BlockEntityType.Builder.of(MechanicalSieveBlockEntity::new, EBlocks.MECHANICAL_SIEVE.get()).build(null)); public static final RegistryObject> MECHANICAL_HAMMER = BLOCK_ENTITIES.register("mechanical_hammer", () -> BlockEntityType.Builder.of(MechanicalHammerBlockEntity::new, EBlocks.MECHANICAL_HAMMER.get()).build(null)); } diff --git a/src/main/java/thedarkcolour/exdeorum/registry/EBlocks.java b/src/main/java/thedarkcolour/exdeorum/registry/EBlocks.java index 5ddf3599..b0627c26 100644 --- a/src/main/java/thedarkcolour/exdeorum/registry/EBlocks.java +++ b/src/main/java/thedarkcolour/exdeorum/registry/EBlocks.java @@ -46,42 +46,6 @@ public class EBlocks { public static final RegistryObject CRUSHED_DEEPSLATE = BLOCKS.register("crushed_deepslate", () -> new FallingBlock(of().mapColor(DyeColor.GRAY).sound(SoundType.SAND).strength(0.8f))); public static final RegistryObject CRUSHED_BLACKSTONE = BLOCKS.register("crushed_blackstone", () -> new FallingBlock(of().mapColor(DyeColor.BLACK).sound(SoundType.SAND).strength(0.6f))); - // Sieves - public static final RegistryObject OAK_SIEVE = registerSieve("oak_sieve"); - public static final RegistryObject SPRUCE_SIEVE = registerSieve("spruce_sieve"); - public static final RegistryObject BIRCH_SIEVE = registerSieve("birch_sieve"); - public static final RegistryObject JUNGLE_SIEVE = registerSieve("jungle_sieve"); - public static final RegistryObject ACACIA_SIEVE = registerSieve("acacia_sieve"); - public static final RegistryObject DARK_OAK_SIEVE = registerSieve("dark_oak_sieve"); - public static final RegistryObject MANGROVE_SIEVE = registerSieve("mangrove_sieve"); - public static final RegistryObject CHERRY_SIEVE = registerSieve("cherry_sieve"); - public static final RegistryObject BAMBOO_SIEVE = registerSieve("bamboo_sieve", SoundType.BAMBOO_WOOD); - public static final RegistryObject CRIMSON_SIEVE = registerSieve("crimson_sieve"); - public static final RegistryObject WARPED_SIEVE = registerSieve("warped_sieve"); - // BOP Sieves - public static final RegistryObject FIR_SIEVE = registerSieve("fir_sieve"); - public static final RegistryObject REDWOOD_SIEVE = registerSieve("redwood_sieve"); - public static final RegistryObject MAHOGANY_SIEVE = registerSieve("mahogany_sieve"); - public static final RegistryObject JACARANDA_SIEVE = registerSieve("jacaranda_sieve"); - public static final RegistryObject PALM_SIEVE = registerSieve("palm_sieve"); - public static final RegistryObject WILLOW_SIEVE = registerSieve("willow_sieve"); - public static final RegistryObject DEAD_SIEVE = registerSieve("dead_sieve"); - public static final RegistryObject MAGIC_SIEVE = registerSieve("magic_sieve"); - public static final RegistryObject UMBRAN_SIEVE = registerSieve("umbran_sieve"); - public static final RegistryObject HELLBARK_SIEVE = registerSieve("hellbark_sieve"); - // Ars Nouveau Sieves - public static final RegistryObject ARCHWOOD_SIEVE = registerSieve("archwood_sieve"); - // Aether Sieves - public static final RegistryObject SKYROOT_SIEVE = registerSieve("skyroot_sieve"); - // Blue Skies Sieves - public static final RegistryObject BLUEBRIGHT_SIEVE = registerSieve("bluebright_sieve"); - public static final RegistryObject STARLIT_SIEVE = registerSieve("starlit_sieve"); - public static final RegistryObject FROSTBRIGHT_SIEVE = registerSieve("frostbright_sieve"); - public static final RegistryObject COMET_SIEVE = registerSieve("comet_sieve"); - public static final RegistryObject LUNAR_SIEVE = registerSieve("lunar_sieve"); - public static final RegistryObject DUSK_SIEVE = registerSieve("dusk_sieve"); - public static final RegistryObject MAPLE_SIEVE = registerSieve("maple_sieve"); - public static final RegistryObject CRYSTALLIZED_SIEVE = registerSieve("crystallized_sieve", SoundType.GLASS); // Mechanical Sieve public static final RegistryObject MECHANICAL_SIEVE = BLOCKS.register("mechanical_sieve", () -> new MechanicalSieveBlock(of().mapColor(MapColor.METAL).requiresCorrectToolForDrops().strength(5f, 1200f))); // Mechanical Hammer diff --git a/src/main/java/thedarkcolour/exdeorum/registry/EItems.java b/src/main/java/thedarkcolour/exdeorum/registry/EItems.java index 02e68abf..892fe53a 100644 --- a/src/main/java/thedarkcolour/exdeorum/registry/EItems.java +++ b/src/main/java/thedarkcolour/exdeorum/registry/EItems.java @@ -19,11 +19,7 @@ package thedarkcolour.exdeorum.registry; import net.minecraft.world.food.FoodProperties; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.Tiers; +import net.minecraft.world.item.*; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.material.Fluids; @@ -34,7 +30,7 @@ import net.minecraftforge.registries.RegistryObject; import thedarkcolour.exdeorum.ExDeorum; import thedarkcolour.exdeorum.compat.ModIds; import thedarkcolour.exdeorum.item.*; -import thedarkcolour.exdeorum.material.BarrelMaterial; +import thedarkcolour.exdeorum.material.DefaultMaterials; import thedarkcolour.exdeorum.recipe.RecipeUtil; import thedarkcolour.exdeorum.tag.EItemTags; @@ -150,42 +146,6 @@ public class EItems { public static final RegistryObject CRUSHED_DEEPSLATE = registerItemBlock(EBlocks.CRUSHED_DEEPSLATE); public static final RegistryObject CRUSHED_BLACKSTONE = registerItemBlock(EBlocks.CRUSHED_BLACKSTONE); - // Sieves - public static final RegistryObject OAK_SIEVE = registerItemBlock(EBlocks.OAK_SIEVE); - public static final RegistryObject SPRUCE_SIEVE = registerItemBlock(EBlocks.SPRUCE_SIEVE); - public static final RegistryObject BIRCH_SIEVE = registerItemBlock(EBlocks.BIRCH_SIEVE); - public static final RegistryObject JUNGLE_SIEVE = registerItemBlock(EBlocks.JUNGLE_SIEVE); - public static final RegistryObject ACACIA_SIEVE = registerItemBlock(EBlocks.ACACIA_SIEVE); - public static final RegistryObject DARK_OAK_SIEVE = registerItemBlock(EBlocks.DARK_OAK_SIEVE); - public static final RegistryObject MANGROVE_SIEVE = registerItemBlock(EBlocks.MANGROVE_SIEVE); - public static final RegistryObject CHERRY_SIEVE = registerItemBlock(EBlocks.CHERRY_SIEVE); - public static final RegistryObject BAMBOO_SIEVE = registerItemBlock(EBlocks.BAMBOO_SIEVE); - public static final RegistryObject CRIMSON_SIEVE = registerItemBlock(EBlocks.CRIMSON_SIEVE); - public static final RegistryObject WARPED_SIEVE = registerItemBlock(EBlocks.WARPED_SIEVE); - // BOP Sieves - public static final RegistryObject FIR_SIEVE = registerItemBlock(EBlocks.FIR_SIEVE); - public static final RegistryObject REDWOOD_SIEVE = registerItemBlock(EBlocks.REDWOOD_SIEVE); - public static final RegistryObject MAHOGANY_SIEVE = registerItemBlock(EBlocks.MAHOGANY_SIEVE); - public static final RegistryObject JACARANDA_SIEVE = registerItemBlock(EBlocks.JACARANDA_SIEVE); - public static final RegistryObject PALM_SIEVE = registerItemBlock(EBlocks.PALM_SIEVE); - public static final RegistryObject WILLOW_SIEVE = registerItemBlock(EBlocks.WILLOW_SIEVE); - public static final RegistryObject DEAD_SIEVE = registerItemBlock(EBlocks.DEAD_SIEVE); - public static final RegistryObject MAGIC_SIEVE = registerItemBlock(EBlocks.MAGIC_SIEVE); - public static final RegistryObject UMBRAN_SIEVE = registerItemBlock(EBlocks.UMBRAN_SIEVE); - public static final RegistryObject HELLBARK_SIEVE = registerItemBlock(EBlocks.HELLBARK_SIEVE); - // Ars Nouveau Sieves - public static final RegistryObject ARCHWOOD_SIEVE = registerItemBlock(EBlocks.ARCHWOOD_SIEVE); - // Aether Sieves - public static final RegistryObject SKYROOT_SIEVE = registerItemBlock(EBlocks.SKYROOT_SIEVE); - // Blue Skies Sieves - public static final RegistryObject BLUEBRIGHT_SIEVE = registerItemBlock(EBlocks.BLUEBRIGHT_SIEVE); - public static final RegistryObject STARLIT_SIEVE = registerItemBlock(EBlocks.STARLIT_SIEVE); - public static final RegistryObject FROSTBRIGHT_SIEVE = registerItemBlock(EBlocks.FROSTBRIGHT_SIEVE); - public static final RegistryObject COMET_SIEVE = registerItemBlock(EBlocks.COMET_SIEVE); - public static final RegistryObject LUNAR_SIEVE = registerItemBlock(EBlocks.LUNAR_SIEVE); - public static final RegistryObject DUSK_SIEVE = registerItemBlock(EBlocks.DUSK_SIEVE); - public static final RegistryObject MAPLE_SIEVE = registerItemBlock(EBlocks.MAPLE_SIEVE); - public static final RegistryObject CRYSTALLIZED_SIEVE = registerItemBlock(EBlocks.CRYSTALLIZED_SIEVE); // Mechanical Sieves public static final RegistryObject MECHANICAL_SIEVE = registerItemBlock(EBlocks.MECHANICAL_SIEVE); public static final RegistryObject MECHANICAL_HAMMER = registerItemBlock(EBlocks.MECHANICAL_HAMMER); @@ -247,52 +207,18 @@ public class EItems { boolean aether = ModList.get().isLoaded(ModIds.AETHER); boolean blueSkies = ModList.get().isLoaded(ModIds.BLUE_SKIES); - for (var material : BarrelMaterial.REGISTERED_MATERIALS) { + for (var material : DefaultMaterials.BARRELS) { if (ModList.get().isLoaded(material.requiredModId)) { output.accept(material.getItem()); } } - output.accept(OAK_SIEVE.get()); - output.accept(SPRUCE_SIEVE.get()); - output.accept(BIRCH_SIEVE.get()); - output.accept(JUNGLE_SIEVE.get()); - output.accept(ACACIA_SIEVE.get()); - output.accept(DARK_OAK_SIEVE.get()); - output.accept(MANGROVE_SIEVE.get()); - output.accept(CHERRY_SIEVE.get()); - output.accept(BAMBOO_SIEVE.get()); - output.accept(CRIMSON_SIEVE.get()); - output.accept(WARPED_SIEVE.get()); + for (var material : DefaultMaterials.SIEVES) { + if (ModList.get().isLoaded(material.requiredModId)) { + output.accept(material.getItem()); + } + } - if (biomesOPlenty) { - output.accept(FIR_SIEVE.get()); - output.accept(REDWOOD_SIEVE.get()); - output.accept(MAHOGANY_SIEVE.get()); - output.accept(JACARANDA_SIEVE.get()); - output.accept(PALM_SIEVE.get()); - output.accept(WILLOW_SIEVE.get()); - output.accept(DEAD_SIEVE.get()); - output.accept(MAGIC_SIEVE.get()); - output.accept(UMBRAN_SIEVE.get()); - output.accept(HELLBARK_SIEVE.get()); - } - if (arsNouveau) { - output.accept(ARCHWOOD_SIEVE.get()); - } - if (aether) { - output.accept(SKYROOT_SIEVE.get()); - } - if (blueSkies) { - output.accept(BLUEBRIGHT_SIEVE.get()); - output.accept(STARLIT_SIEVE.get()); - output.accept(FROSTBRIGHT_SIEVE.get()); - output.accept(COMET_SIEVE.get()); - output.accept(LUNAR_SIEVE.get()); - output.accept(DUSK_SIEVE.get()); - output.accept(MAPLE_SIEVE.get()); - output.accept(CRYSTALLIZED_SIEVE.get()); - } output.accept(MECHANICAL_SIEVE.get()); output.accept(MECHANICAL_HAMMER.get());