All harvest operations now require and damage a tool (either hoe or axe)

This commit is contained in:
CrazyPants committed 2014-05-30 10:26:14 +08:00
1 parent e78a6080df
commit 895ecd54e5
6 files changed
+70 -63

No files matched your search

@@ -18,14 +18,14 @@ public class NaturaBerryFarmer extends PickableFarmer {
@Override
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
if(block != getPlantedBlock()) {
if(block != getPlantedBlock() || !farm.hasHarvestTool()) {
return null;
}
IHarvestResult res = new HarvestResult();
BlockCoord checkBlock = bc;
for(int i=0; i < 5; i++) {
for(int i=0; i < 5 && farm.hasHarvestTool(); i++) {
meta = farm.getBlockMeta(checkBlock);
IHarvestResult blockRes = super.harvestBlock(farm, checkBlock, block, meta);
@@ -35,13 +35,15 @@ public class NaturaBerryFarmer extends PickableFarmer {
for(EntityItem stack : addToDrops) {
res.getDrops().add(stack);
}
farm.actionPerformed();
farm.damageMaxLootingItem();
}
checkBlock = checkBlock.getLocation(ForgeDirection.UP);
}
if(res.getHarvestedBlocks().isEmpty()) {
return null;
}
}
return res;
}
@@ -23,10 +23,7 @@ public class NetherWartFarmer extends SeedFarmer {
World worldObj = farm.getWorldObj();
BlockCoord grn = bc.getLocation(ForgeDirection.DOWN);
Block blk = worldObj.getBlock(grn.x, grn.y, grn.z);
if(blk == Blocks.soul_sand) {
System.out.println("NetherWartFarmer.prepareBlock: !!");
}
return plantFromInvenetory(farm, bc);
}
@@ -29,7 +29,7 @@ public class PickableFarmer extends SeedFarmer {
@Override
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
if(!canHarvest(farm, bc, block, meta)) {
if(!canHarvest(farm, bc, block, meta) || !farm.hasHarvestTool()) {
return null;
}
EntityPlayerMP player = farm.getFakePlayer();
@@ -48,7 +48,8 @@ public class PickableFarmer extends SeedFarmer {
drops.add(entityitem);
}
}
farm.actionPerformed();
farm.damageMaxLootingItem();
return new HarvestResult(drops, bc);
}
@@ -103,7 +103,7 @@ public class SeedFarmer implements IFarmerJoe {
@Override
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
if(!canHarvest(farm, bc, block, meta)) {
if(!canHarvest(farm, bc, block, meta) || !farm.hasHarvestTool()) {
return null;
}
@@ -38,12 +38,14 @@ public class StemFarmer extends SeedFarmer {
@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)) {
if(plantedBlock == farm.getBlock(harvestCoord) && farm.hasHarvestTool()) {
res.harvestedBlocks.add(harvestCoord);
ArrayList<ItemStack> drops = plantedBlock.getDrops(farm.getWorld(), harvestCoord.x, harvestCoord.y, harvestCoord.z, meta, farm.getMaxLootingValue());
if(drops != null) {
@@ -70,28 +70,6 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
powerHandler = PowerHandlerUtil.createHandler(cap, this, Type.MACHINE);
}
public boolean hasHoe() {
return hasTool(ItemHoe.class);
}
public boolean hasAxe() {
return hasTool(ItemAxe.class);
}
public int geAxeLootingValue() {
ItemStack tool = getTool(ItemAxe.class);
if(tool == null) {
return 0;
}
return getLooting(tool);
}
private int getLooting(ItemStack stack) {
return Math.max(
EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, stack),
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));
}
public int getFarmSize() {
return farmSize;
}
@@ -103,7 +81,58 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
public void actionPerformed() {
usePower(Config.farmActionEnergyUse);
}
public int getMaxLootingValue() {
int result = 0;
for (int i = minToolSlot; i <= maxToolSlot; i++) {
if(inventory[i] != null) {
int level = getLooting(inventory[i]);
if(level > result) {
result = level;
}
}
}
return result;
}
public void damageMaxLootingItem() {
int maxLooting = -1;
ItemStack toDamage = null;
for (int i = minToolSlot; i <= maxToolSlot; i++) {
if(inventory[i] != null) {
int level = getLooting(inventory[i]);
if(level > maxLooting) {
maxLooting = level;
toDamage = inventory[i];
}
}
}
if(toDamage != null) {
damageTool(toDamage.getItem().getClass(), 1);
}
}
public boolean hasHoe() {
return hasTool(ItemHoe.class);
}
public boolean hasAxe() {
return hasTool(ItemAxe.class);
}
public boolean hasHarvestTool() {
return hasAxe() || hasHoe();
}
public int geAxeLootingValue() {
ItemStack tool = getTool(ItemAxe.class);
if(tool == null) {
return 0;
}
return getLooting(tool);
}
public void damageAxe() {
damageTool(ItemAxe.class, 1);
}
@@ -145,41 +174,17 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
}
}
}
private int getLooting(ItemStack stack) {
return Math.max(
EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, stack),
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));
}
public EntityPlayerMP getFakePlayer() {
return farmerJoe;
}
public int getMaxLootingValue() {
int result = 0;
for (int i = minToolSlot; i <= maxToolSlot; i++) {
if(inventory[i] != null) {
int level = getLooting(inventory[i]);
if(level > result) {
result = level;
}
}
}
return result;
}
public void damageMaxLootingItem() {
int maxLooting = 0;
ItemStack toDamage = null;
for (int i = minToolSlot; i <= maxToolSlot; i++) {
if(inventory[i] != null) {
int level = getLooting(inventory[i]);
if(level > maxLooting) {
maxLooting = level;
toDamage = inventory[i];
}
}
}
if(toDamage != null) {
toDamage.damageItem(1, farmerJoe);
}
}
public Block getBlock(BlockCoord bc) {
return worldObj.getBlock(bc.x, bc.y, bc.z);
}