diff --git a/build.gradle b/build.gradle index c567cbba1..80492f135 100644 --- a/build.gradle +++ b/build.gradle @@ -115,7 +115,7 @@ dependencies { modRuntimeOnly "vazkii.patchouli:Patchouli:$patchouliVersion-FORGE" // ModKit DEV ONLY modImplementation 'com.github.thedarkcolour:ModKit:cc8f1c11ec' - + // DEV ONLY compileOnly "org.jetbrains:annotations:23.0.0" } diff --git a/src/main/java/forestry/compat/pamhccrops/PamHC2CropsCompat.java b/src/main/java/forestry/compat/pamhccrops/PamHC2CropsCompat.java new file mode 100644 index 000000000..2db116b9f --- /dev/null +++ b/src/main/java/forestry/compat/pamhccrops/PamHC2CropsCompat.java @@ -0,0 +1,48 @@ +//Compat added by https://github.com/TimeyDingo +package forestry.compat.pamhccrops; + +import forestry.api.plugin.IFarmTypeBuilder; +import forestry.farming.logic.farmables.FarmableAgingCrop; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraft.world.level.block.CropBlock; + +public class PamHC2CropsCompat { + + public static void registerPamCrops(IFarmTypeBuilder crops) { + if (!ModList.get().isLoaded("pamhc2crops")) { + return; + } + + for (ResourceLocation id : ForgeRegistries.BLOCKS.getKeys()) { // testing automated gathering of registerys + if (!id.getNamespace().equals("pamhc2crops")) continue; + + String path = id.getPath(); // like "pamcorncrop" + if (!path.startsWith("pam") || !path.endsWith("crop")) continue; + + // extract crop name: pam + corn + crop → corn + String cropName = path.substring(3, path.length() - 4); // between "pam" and "crop" + String CropItemID = cropName + "item"; + String SeedItemID = cropName + "seed" + "item"; + //example "agaveseeditem" + //example "agaveitem" + addPamCrop(crops, CropItemID, path, SeedItemID); + } + } + + private static void addPamCrop(IFarmTypeBuilder crops, String CropItemID, String blockId, String SeedItemID) { + Item cropitem = ForgeRegistries.ITEMS.getValue(new ResourceLocation("pamhc2crops", CropItemID)); // Pams crops can be planted directly or converted to seeds before planting so both are needed + Item seeditem = ForgeRegistries.ITEMS.getValue(new ResourceLocation("pamhc2crops", SeedItemID)); + Block cropBlock = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("pamhc2crops", blockId)); + if (cropitem != null && cropBlock instanceof CropBlock) { + //crops.addFarmable(new FarmableAgingCrop(Items.CARROT, Blocks.CARROTS, new ItemStack(Items.CARROT), CropBlock.AGE, 7, 0)); + //crops.addFarmable(new FarmableAgingCrop(Items.BEETROOT_SEEDS, Blocks.BEETROOTS, new ItemStack(Items.BEETROOT), BeetrootBlock.AGE, 3, 0)); + crops.addFarmable(new FarmableAgingCrop(cropitem, cropBlock, new ItemStack(cropitem), CropBlock.AGE, 5, 0)); + crops.addFarmable(new FarmableAgingCrop(seeditem, cropBlock, new ItemStack(cropitem), CropBlock.AGE, 5, 0)); + } + } +} diff --git a/src/main/java/forestry/compat/pamhccrops/package-info.java b/src/main/java/forestry/compat/pamhccrops/package-info.java new file mode 100644 index 000000000..a5e75413c --- /dev/null +++ b/src/main/java/forestry/compat/pamhccrops/package-info.java @@ -0,0 +1,4 @@ +@javax.annotation.ParametersAreNonnullByDefault +@forestry.core.utils.FieldsAreNonnullByDefault +@net.minecraft.MethodsReturnNonnullByDefault +package forestry.compat.pamhccrops; diff --git a/src/main/java/forestry/plugin/DefaultFarms.java b/src/main/java/forestry/plugin/DefaultFarms.java index d3e7cf92e..0d4b55d31 100644 --- a/src/main/java/forestry/plugin/DefaultFarms.java +++ b/src/main/java/forestry/plugin/DefaultFarms.java @@ -23,6 +23,8 @@ import net.minecraft.world.level.block.CropBlock; import net.minecraft.world.level.block.NetherWartBlock; +import forestry.compat.pamhccrops.PamHC2CropsCompat; + import java.util.List; public class DefaultFarms { @@ -148,5 +150,6 @@ private static void addCropFarmables(IFarmTypeBuilder crops) { crops.addFarmable(new FarmableAgingCrop(Items.POTATO, Blocks.POTATOES, new ItemStack(Items.POTATO), CropBlock.AGE, 7, 0)); crops.addFarmable(new FarmableAgingCrop(Items.CARROT, Blocks.CARROTS, new ItemStack(Items.CARROT), CropBlock.AGE, 7, 0)); crops.addFarmable(new FarmableAgingCrop(Items.BEETROOT_SEEDS, Blocks.BEETROOTS, new ItemStack(Items.BEETROOT), BeetrootBlock.AGE, 3, 0)); + PamHC2CropsCompat.registerPamCrops(crops); } }