mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 15:03:07 +00:00
Added farm support for Natura cotton and barley.
This commit is contained in:
1 parent
bbda836954
commit
ebe0d61e47
7 files changed
+121
-15
No files matched your search
@@ -49,6 +49,7 @@ import crazypants.enderio.machine.alloy.BlockAlloySmelter;
|
||||
import crazypants.enderio.machine.crusher.BlockCrusher;
|
||||
import crazypants.enderio.machine.crusher.CrusherRecipeManager;
|
||||
import crazypants.enderio.machine.farm.BlockFarmStation;
|
||||
import crazypants.enderio.machine.farm.ModdedCrops;
|
||||
import crazypants.enderio.machine.generator.BlockCombustionGenerator;
|
||||
import crazypants.enderio.machine.generator.BlockStirlingGenerator;
|
||||
import crazypants.enderio.machine.hypercube.BlockHyperCube;
|
||||
@@ -369,6 +370,7 @@ public class EnderIO {
|
||||
CrusherRecipeManager.getInstance().loadRecipesFromConfig();
|
||||
AlloyRecipeManager.getInstance().loadRecipesFromConfig();
|
||||
VatRecipeManager.getInstance().loadRecipesFromConfig();
|
||||
ModdedCrops.addModdedFarmers();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -3,9 +3,12 @@ package crazypants.enderio.machine.farm;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
@@ -30,7 +33,7 @@ public class FarmersComune implements IFarmerJoe {
|
||||
joinComune(new StemFarmer(Blocks.reeds, new ItemStack(Items.reeds)));
|
||||
joinComune(new StemFarmer(Blocks.cactus, new ItemStack(Blocks.cactus)));
|
||||
joinComune(new TreeFarmer(Blocks.sapling, Blocks.log));
|
||||
joinComune(new TreeFarmer(Blocks.sapling, Blocks.log2));
|
||||
joinComune(new TreeFarmer(Blocks.sapling, Blocks.log2));
|
||||
}
|
||||
|
||||
private List<IFarmerJoe> farmers = new ArrayList<IFarmerJoe>();
|
||||
|
||||
@@ -18,7 +18,7 @@ public class HarvestResult implements IHarvestResult {
|
||||
|
||||
public HarvestResult(List<EntityItem> drops, BlockCoord harvestedBlock) {
|
||||
this.drops = drops;
|
||||
this.harvestedBlocks = new ArrayList<BlockCoord>();
|
||||
this.harvestedBlocks = new ArrayList<BlockCoord>();
|
||||
harvestedBlocks.add(harvestedBlock);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public final class ModdedCrops {
|
||||
|
||||
//System.out.println("FarmersComune.enclosing_method: ");
|
||||
|
||||
public static void addModdedFarmers() {
|
||||
String natura = "Natura";
|
||||
String cropsItem = "N Crops";
|
||||
|
||||
Block natCropBlock = GameRegistry.findBlock(natura, cropsItem);
|
||||
if(natCropBlock != null) {
|
||||
Item natSeedItem = GameRegistry.findItem(natura, "barley.seed");
|
||||
if(natSeedItem != null) {
|
||||
//barley
|
||||
FarmersComune.instance.joinComune(new SeedFarmer(natCropBlock, 3, new ItemStack(natSeedItem)));
|
||||
// cotton
|
||||
FarmersComune.instance.joinComune(new PickableFarmer(natCropBlock, 4, 8, new ItemStack(natSeedItem, 1, 1)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ModdedCrops() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import crazypants.util.BlockCoord;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PickableFarmer extends SeedFarmer {
|
||||
|
||||
public PickableFarmer(Block plantedBlock, int plantedBlockMeta, int grownBlockMeta, ItemStack seeds) {
|
||||
super(plantedBlock, plantedBlockMeta, grownBlockMeta, seeds);
|
||||
}
|
||||
|
||||
public PickableFarmer(Block plantedBlock, int grownBlockMeta, ItemStack seeds) {
|
||||
super(plantedBlock, grownBlockMeta, seeds);
|
||||
}
|
||||
|
||||
public PickableFarmer(Block plantedBlock, ItemStack seeds) {
|
||||
super(plantedBlock, seeds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
|
||||
if(!canHarvest(farm, bc, block, meta)) {
|
||||
return null;
|
||||
}
|
||||
EntityPlayerMP player = farm.getFakePlayer();
|
||||
World world = farm.getWorldObj();
|
||||
player.theItemInWorldManager.activateBlockOrUseItem(player, player.worldObj, null, bc.x, bc.y, bc.z, 0, 0, 0, 0);
|
||||
|
||||
List<EntityItem> drops = new ArrayList<EntityItem>();
|
||||
|
||||
ItemStack[] inv = player.inventory.mainInventory;
|
||||
for(int slot=0;slot < inv.length;slot++) {
|
||||
ItemStack stack = inv[slot];
|
||||
if(stack != null) {
|
||||
inv[slot] = null;
|
||||
float f = 0.7F;
|
||||
double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
EntityItem entityitem = new EntityItem(world, bc.x + d0, bc.y + d1, bc.z + d2, stack);
|
||||
drops.add(entityitem);
|
||||
}
|
||||
}
|
||||
|
||||
return new HarvestResult(drops, bc);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -15,16 +15,16 @@ import crazypants.util.BlockCoord;
|
||||
public class SeedFarmer implements IFarmerJoe {
|
||||
|
||||
protected Block plantedBlock;
|
||||
protected int plantedBlockMeta;
|
||||
protected int plantedBlockMeta;
|
||||
protected int grownBlockMeta;
|
||||
protected ItemStack seeds;
|
||||
|
||||
public SeedFarmer(Block plantedBlock, ItemStack seeds) {
|
||||
this(plantedBlock, 0,7,seeds);
|
||||
this(plantedBlock, 0, 7, seeds);
|
||||
}
|
||||
|
||||
public SeedFarmer(Block plantedBlock, int grownBlockMeta, ItemStack seeds) {
|
||||
this(plantedBlock,0,grownBlockMeta,seeds);
|
||||
this(plantedBlock, 0, grownBlockMeta, seeds);
|
||||
}
|
||||
|
||||
public SeedFarmer(Block plantedBlock, int plantedBlockMeta, int grownBlockMeta, ItemStack seeds) {
|
||||
@@ -68,19 +68,25 @@ public class SeedFarmer implements IFarmerJoe {
|
||||
if(block != Blocks.air) {
|
||||
return false;
|
||||
}
|
||||
World worldObj = farm.getWorldObj();
|
||||
if(isGroundTilled(farm, bc)) {
|
||||
return plantFromInvenetory(farm, bc);
|
||||
}
|
||||
if(farm.hasSeed(getSeeds(), bc)) {
|
||||
boolean tilled= tillBlock(farm, bc);
|
||||
if(!tilled) {
|
||||
return false;
|
||||
if(requiresFarmland()) {
|
||||
World worldObj = farm.getWorldObj();
|
||||
if(isGroundTilled(farm, bc)) {
|
||||
return plantFromInvenetory(farm, bc);
|
||||
}
|
||||
if(farm.hasSeed(getSeeds(), bc)) {
|
||||
boolean tilled = tillBlock(farm, bc);
|
||||
if(!tilled) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return plantFromInvenetory(farm, bc);
|
||||
}
|
||||
|
||||
protected boolean requiresFarmland() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean plantFromInvenetory(TileFarmStation farm, BlockCoord bc) {
|
||||
World worldObj = farm.getWorldObj();
|
||||
if(canPlant(worldObj, bc) && farm.getSeedFromSupplies(getSeeds(), bc) != null) {
|
||||
@@ -129,6 +135,7 @@ public class SeedFarmer implements IFarmerJoe {
|
||||
return new HarvestResult(result, bc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected boolean tillBlock(TileFarmStation farm, BlockCoord plantingLocation) {
|
||||
World worldObj = farm.getWorldObj();
|
||||
@@ -155,7 +162,7 @@ public class SeedFarmer implements IFarmerJoe {
|
||||
IPlantable plantable = (IPlantable) getPlantedBlock();
|
||||
if(target.canPlaceBlockAt(worldObj, bc.x, bc.y, bc.z) &&
|
||||
target.canBlockStay(worldObj, bc.x, bc.y, bc.z) &&
|
||||
ground.canSustainPlant(worldObj, bc.x, bc.y -1, bc.z, ForgeDirection.UP, plantable)) {
|
||||
ground.canSustainPlant(worldObj, bc.x, bc.y - 1, bc.z, ForgeDirection.UP, plantable)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.IProjectile;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemAxe;
|
||||
@@ -131,7 +132,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
|
||||
|
||||
|
||||
|
||||
public EntityPlayer getFakePlayer() {
|
||||
public EntityPlayerMP getFakePlayer() {
|
||||
return farmerJoe;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user