mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 05:02:25 +00:00
Added suuport for sugar cane and cactus.
This commit is contained in:
1 parent
7dcd024c18
commit
df97243d0a
7 files changed
+97
-22
No files matched your search
@@ -23,10 +23,12 @@ public class FarmersComune implements IFarmerJoe {
|
||||
}
|
||||
|
||||
static {
|
||||
joinComune(new DefaultSeedFarmer(Blocks.potatoes, new ItemStack(Items.potato)));
|
||||
joinComune(new DefaultSeedFarmer(Blocks.wheat, new ItemStack(Items.wheat_seeds)));
|
||||
joinComune(new DefaultSeedFarmer(Blocks.carrots, new ItemStack(Items.carrot)));
|
||||
joinComune(new SeedFarmer(Blocks.potatoes, new ItemStack(Items.potato)));
|
||||
joinComune(new SeedFarmer(Blocks.wheat, new ItemStack(Items.wheat_seeds)));
|
||||
joinComune(new SeedFarmer(Blocks.carrots, new ItemStack(Items.carrot)));
|
||||
joinComune(new NetherWartFarmer());
|
||||
joinComune(new StemFarmer(Blocks.reeds, new ItemStack(Items.reeds)));
|
||||
joinComune(new StemFarmer(Blocks.cactus, new ItemStack(Blocks.cactus)));
|
||||
}
|
||||
|
||||
private List<IFarmerJoe> farmers = new ArrayList<IFarmerJoe>();
|
||||
|
||||
@@ -22,6 +22,11 @@ public class HarvestResult implements IHarvestResult {
|
||||
harvestedBlocks.add(harvestedBlock);
|
||||
}
|
||||
|
||||
public HarvestResult() {
|
||||
drops = new ArrayList<EntityItem>();
|
||||
harvestedBlocks = new ArrayList<BlockCoord>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntityItem> getDrops() {
|
||||
return drops;
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class NetherWartFarmer extends DefaultSeedFarmer {
|
||||
public class NetherWartFarmer extends SeedFarmer {
|
||||
|
||||
public NetherWartFarmer() {
|
||||
super(Blocks.nether_wart, 3, new ItemStack(Items.nether_wart));
|
||||
|
||||
+7
-11
@@ -12,22 +12,22 @@ import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class DefaultSeedFarmer implements IFarmerJoe {
|
||||
public class SeedFarmer implements IFarmerJoe {
|
||||
|
||||
protected Block plantedBlock;
|
||||
protected int plantedBlockMeta;
|
||||
protected int grownBlockMeta;
|
||||
protected ItemStack seeds;
|
||||
|
||||
public DefaultSeedFarmer(Block plantedBlock, ItemStack seeds) {
|
||||
public SeedFarmer(Block plantedBlock, ItemStack seeds) {
|
||||
this(plantedBlock, 0,7,seeds);
|
||||
}
|
||||
|
||||
public DefaultSeedFarmer(Block plantedBlock, int grownBlockMeta, ItemStack seeds) {
|
||||
public SeedFarmer(Block plantedBlock, int grownBlockMeta, ItemStack seeds) {
|
||||
this(plantedBlock,0,grownBlockMeta,seeds);
|
||||
}
|
||||
|
||||
public DefaultSeedFarmer(Block plantedBlock, int plantedBlockMeta, int grownBlockMeta, ItemStack seeds) {
|
||||
public SeedFarmer(Block plantedBlock, int plantedBlockMeta, int grownBlockMeta, ItemStack seeds) {
|
||||
this.plantedBlock = plantedBlock;
|
||||
this.plantedBlockMeta = plantedBlockMeta;
|
||||
this.grownBlockMeta = grownBlockMeta;
|
||||
@@ -72,7 +72,6 @@ public class DefaultSeedFarmer implements IFarmerJoe {
|
||||
if(isGroundTilled(farm, bc)) {
|
||||
return plantFromInvenetory(farm, bc);
|
||||
}
|
||||
|
||||
if(farm.hasSeed(getSeeds(), bc)) {
|
||||
boolean tilled= tillBlock(farm, bc);
|
||||
if(!tilled) {
|
||||
@@ -133,7 +132,7 @@ public class DefaultSeedFarmer implements IFarmerJoe {
|
||||
protected boolean tillBlock(TileFarmStation farm, BlockCoord plantingLocation) {
|
||||
World worldObj = farm.getWorldObj();
|
||||
BlockCoord dirtLoc = plantingLocation.getLocation(ForgeDirection.DOWN);
|
||||
Block dirtBlock = worldObj.getBlock(dirtLoc.x, dirtLoc.y, dirtLoc.z);
|
||||
Block dirtBlock = farm.getBlock(dirtLoc);
|
||||
if((dirtBlock == Blocks.dirt || dirtBlock == Blocks.grass) && farm.hasHoe()) {
|
||||
worldObj.setBlock(dirtLoc.x, dirtLoc.y, dirtLoc.z, Blocks.farmland);
|
||||
worldObj.playSoundEffect(dirtLoc.x + 0.5F, dirtLoc.y + 0.5F, dirtLoc.z + 0.5F, Blocks.farmland.stepSound.getStepResourcePath(),
|
||||
@@ -145,10 +144,7 @@ public class DefaultSeedFarmer implements IFarmerJoe {
|
||||
}
|
||||
|
||||
protected boolean isGroundTilled(TileFarmStation farm, BlockCoord plantingLocation) {
|
||||
World worldObj = farm.getWorldObj();
|
||||
BlockCoord dirtLoc = plantingLocation.getLocation(ForgeDirection.DOWN);
|
||||
Block dirtBlock = worldObj.getBlock(dirtLoc.x, dirtLoc.y, dirtLoc.z);
|
||||
return dirtBlock == Blocks.farmland;
|
||||
return farm.getBlock(plantingLocation.getLocation(ForgeDirection.DOWN)) == Blocks.farmland;
|
||||
}
|
||||
|
||||
protected boolean canPlant(World worldObj, BlockCoord bc) {
|
||||
@@ -157,7 +153,7 @@ public class DefaultSeedFarmer 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, bc.z, ForgeDirection.UP, plantable)) {
|
||||
ground.canSustainPlant(worldObj, bc.x, bc.y -1, bc.z, ForgeDirection.UP, plantable)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -0,0 +1,74 @@
|
||||
package crazypants.enderio.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class StemFarmer extends SeedFarmer {
|
||||
|
||||
|
||||
public StemFarmer(Block plantedBlock, ItemStack seeds) {
|
||||
super(plantedBlock, seeds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
if(plantedBlock == block) {
|
||||
return true;
|
||||
}
|
||||
return plantFromInvenetory(farm, bc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvest(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
BlockCoord up = bc.getLocation(ForgeDirection.UP);
|
||||
Block upBLock = farm.getBlock(up);
|
||||
return upBLock == plantedBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlant(ItemStack stack) {
|
||||
return seeds.isItemEqual(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
HarvestResult res = new HarvestResult();
|
||||
BlockCoord harvestCoord = bc;
|
||||
boolean done = false;
|
||||
do{
|
||||
harvestCoord = harvestCoord.getLocation(ForgeDirection.UP);
|
||||
if(plantedBlock == farm.getBlock(harvestCoord)) {
|
||||
res.harvestedBlocks.add(harvestCoord);
|
||||
ArrayList<ItemStack> drops = plantedBlock.getDrops(farm.getWorld(), harvestCoord.x, harvestCoord.y, harvestCoord.z, meta, farm.getMaxLootingValue());
|
||||
if(drops != null) {
|
||||
for(ItemStack drop : drops) {
|
||||
res.drops.add(new EntityItem(farm.getWorld(), bc.x + 0.5, bc.y + 0.5, bc.z + 0.5, drop.copy()));
|
||||
}
|
||||
|
||||
}
|
||||
farm.damageMaxLootingItem();
|
||||
farm.getWorld().setBlockToAir(harvestCoord.x, harvestCoord.y, harvestCoord.z);
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
} while(!done);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean plantFromInvenetory(TileFarmStation farm, BlockCoord bc) {
|
||||
World worldObj = farm.getWorldObj();
|
||||
if(canPlant(worldObj, bc) && farm.getSeedFromSupplies(seeds, bc)) {
|
||||
return plant(worldObj, bc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
|
||||
private crazypants.util.BlockCoord lastScanned;
|
||||
private FakePlayer farmerJoe;
|
||||
|
||||
private int farmSize = 3;
|
||||
private int farmSize = 1;
|
||||
private int minToolSlot = 0;
|
||||
private int maxToolSlot = 1;
|
||||
|
||||
@@ -111,6 +111,10 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
|
||||
}
|
||||
}
|
||||
|
||||
public Block getBlock(BlockCoord up) {
|
||||
return worldObj.getBlock(up.x, up.y, up.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMachineItemValidForSlot(int i, ItemStack stack) {
|
||||
if(i < 2) {
|
||||
@@ -383,5 +387,4 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package crazypants.enderio.farm;
|
||||
|
||||
public class WheatFarmerBruce {
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user