Added forestry sapling support to farm station

Cherry picked & backported from 1b242dc2d786b8c1fb545845768faa1f6c15818a
This commit is contained in:
bdew authored and Jason Mitchell committed 2020-11-07 12:50:04 -08:00
1 parent 76dabdf493
commit 7f89eba8b5
3 files changed
+71 -50

No files matched your search

@@ -24,6 +24,7 @@ import crazypants.enderio.machine.farm.farmers.PlantableFarmer;
import crazypants.enderio.machine.farm.farmers.RubberTreeFarmerIC2;
import crazypants.enderio.machine.farm.farmers.StemFarmer;
import crazypants.enderio.machine.farm.farmers.TreeFarmer;
import crazypants.enderio.machine.farm.farmers.ForestryFarmer;
public final class FarmersRegistry {
@@ -34,13 +35,10 @@ public final class FarmersRegistry {
addExtraUtilities();
addNatura();
addTiC();
addStillHungry();
addIC2();
addMFR();
addThaumcraft();
addFlowers();
addGrowableOres();
addImmersiveEngineering();
ForestryFarmer.init();
FarmersCommune.joinCommune(new StemFarmer(Blocks.reeds, new ItemStack(Items.reeds)));
FarmersCommune.joinCommune(new StemFarmer(Blocks.cactus, new ItemStack(Blocks.cactus)));
@@ -178,16 +176,6 @@ public final class FarmersRegistry {
}
}
private static void addMFR() {
String mod = "MineFactoryReloaded";
String blockName = "rubberwood.sapling";
Block saplingBlock = GameRegistry.findBlock(mod, blockName);
if(saplingBlock != null) {
FarmersCommune.joinCommune(new TreeFarmer(saplingBlock, GameRegistry.findBlock(mod, "rubberwood.log")));
}
}
private static void addIC2() {
RubberTreeFarmerIC2 rtf = new RubberTreeFarmerIC2();
if(rtf.isValid()) {
@@ -195,11 +183,6 @@ public final class FarmersRegistry {
}
}
private static void addStillHungry() {
String mod = "stillhungry";
addPickable(mod, "grapeBlock", "StillHungry_grapeSeed");
}
private static void addExtraUtilities() {
String mod = "ExtraUtilities";
String name = "plant/ender_lilly";
@@ -219,36 +202,6 @@ public final class FarmersRegistry {
GameRegistry.findBlock("Botany", "flower"),
GameRegistry.findBlock("Botania", "flower") ) );
}
@SuppressWarnings("unchecked")
private static void addGrowableOres() {
String mod = "B0bGrowsOre";
if (!Loader.isModLoaded(mod)) {
return;
}
Pattern[] growableOres = { Pattern.compile("(.+)Reed"), Pattern.compile("oreGrowable(.+)") };
Iterator<Block> blockIter = Block.blockRegistry.iterator();
while (blockIter.hasNext()) {
Block block = blockIter.next();
String name = Block.blockRegistry.getNameForObject(block);
if (name != null && name.startsWith(mod)) {
for (Pattern blockPattern : growableOres) {
if (blockPattern.matcher(name).find()) {
FarmersCommune.joinCommune(new StemFarmer(block, new ItemStack(block)));
}
}
}
}
}
private static void addImmersiveEngineering() {
Block hemp = GameRegistry.findBlock("ImmersiveEngineering", "hemp");
Item hempSeed = GameRegistry.findItem("ImmersiveEngineering", "hemp");
if (hemp != null && hempSeed != null) {
FarmersCommune.joinCommune(new StemFarmer(hemp, new ItemStack(hempSeed)));
}
}
private FarmersRegistry() {
}
@@ -0,0 +1,68 @@
package crazypants.enderio.machine.farm.farmers;
import com.enderio.core.common.util.BlockCoord;
import cpw.mods.fml.common.registry.GameRegistry;
import crazypants.enderio.Log;
import crazypants.enderio.machine.farm.TileFarmStation;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.ITreeRoot;
import forestry.api.genetics.AlleleManager;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ForestryFarmer implements IFarmerJoe {
private ITreeRoot root;
private Item forestrySapling;
private ForestryFarmer(ITreeRoot root, Item forestrySapling) {
this.root = root;
this.forestrySapling = forestrySapling;
}
public static void init() {
ITreeRoot root = (ITreeRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees");
Item forestrySapling = GameRegistry.findItem("Forestry", "sapling");
if (root != null && forestrySapling != null) {
FarmersCommune.joinCommune(new ForestryFarmer(root, forestrySapling));
Log.info("ForestryFarmer engaged.");
} else {
Log.info("ForestryFarmer borked.");
}
}
@Override
public boolean canPlant(ItemStack stack) {
return stack != null && stack.getItem() == forestrySapling && root.getType(stack) == EnumGermlingType.SAPLING;
}
@Override
public boolean prepareBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
ItemStack sapling = farm.getSeedTypeInSuppliesFor(bc);
ITree tree = root.getMember(sapling);
if (tree != null && tree.canStay(farm.getWorldObj(), bc.x, bc.y, bc.z)) {
farm.takeSeedFromSupplies(sapling, bc, false);
root.plantSapling(farm.getWorldObj(), tree, farm.getFakePlayer().getGameProfile(), bc.x, bc.y, bc.z);
return true;
}
return false;
}
@Override
public boolean canHarvest(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
return false;
}
@Override
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
return null;
}
}