Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/forestry/compat/pamhccrops/PamHC2CropsCompat.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/forestry/compat/pamhccrops/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@javax.annotation.ParametersAreNonnullByDefault
@forestry.core.utils.FieldsAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
package forestry.compat.pamhccrops;
3 changes: 3 additions & 0 deletions src/main/java/forestry/plugin/DefaultFarms.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}