Skip to content

Commit

Permalink
Merge pull request #25 from GTNewHorizons/forestry_compat
Browse files Browse the repository at this point in the history
Added forestry sapling support to farm station
  • Loading branch information
Dream-Master authored Nov 8, 2020
2 parents 76dabdf + 7f89eba commit e2b41a4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 50 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ minecraft_version=1.7.10
forge_version=10.13.4.1614-1.7.10
forgeDep_version=10.13.4.1614

mod_version=2.3.1.13_beta
mod_version=2.3.1.14_beta

#Comment out this line to get rid of the appendix
#mod_appendix=beta
Expand Down
51 changes: 2 additions & 49 deletions src/main/java/crazypants/enderio/machine/farm/FarmersRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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 {

Expand All @@ -34,13 +35,10 @@ public static void addFarmers() {
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)));
Expand Down Expand Up @@ -178,28 +176,13 @@ private static void addThaumcraft()
}
}

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()) {
FarmersCommune.joinCommune(rtf);
}
}

private static void addStillHungry() {
String mod = "stillhungry";
addPickable(mod, "grapeBlock", "StillHungry_grapeSeed");
}

private static void addExtraUtilities() {
String mod = "ExtraUtilities";
String name = "plant/ender_lilly";
Expand All @@ -219,36 +202,6 @@ private static void addFlowers() {
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() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}





}

0 comments on commit e2b41a4

Please sign in to comment.