mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 15:03:07 +00:00
Switch to using proper methods for tool damaging.
Should fix all compatability issues with the farm.
This commit is contained in:
1 parent
a1ff916506
commit
dd3cae97f6
7 files changed
+25
-18
No files matched your search
@@ -2,6 +2,7 @@ package crazypants.enderio.machine.farm;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.play.client.C15PacketClientSettings;
|
||||
import net.minecraft.server.management.ItemInWorldManager;
|
||||
import net.minecraft.stats.StatBase;
|
||||
@@ -74,4 +75,9 @@ public class FakeFarmPlayer extends EntityPlayerMP {
|
||||
public void func_147100_a(C15PacketClientSettings pkt) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerEdit(int par1, int par2, int par3, int par4, ItemStack par5ItemStack) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class NaturaBerryFarmer extends PickableFarmer {
|
||||
res.getDrops().add(stack);
|
||||
}
|
||||
farm.actionPerformed();
|
||||
farm.damageMaxLootingItem();
|
||||
farm.damageMaxLootingItem(1, checkBlock, farm.getBlock(checkBlock));
|
||||
}
|
||||
checkBlock = checkBlock.getLocation(ForgeDirection.UP);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class PickableFarmer extends SeedFarmer {
|
||||
}
|
||||
}
|
||||
farm.actionPerformed();
|
||||
farm.damageMaxLootingItem();
|
||||
farm.damageMaxLootingItem(1, bc, block);
|
||||
return new HarvestResult(drops, bc);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ public class SeedFarmer implements IFarmerJoe {
|
||||
List<EntityItem> result = new ArrayList<EntityItem>();
|
||||
|
||||
ArrayList<ItemStack> drops = block.getDrops(worldObj, bc.x, bc.y, bc.z, meta, farm.getMaxLootingValue());
|
||||
farm.damageMaxLootingItem();
|
||||
farm.damageMaxLootingItem(1, bc, block);
|
||||
farm.actionPerformed();
|
||||
boolean removed = false;
|
||||
if(drops != null) {
|
||||
@@ -147,10 +147,10 @@ public class SeedFarmer implements IFarmerJoe {
|
||||
BlockCoord dirtLoc = plantingLocation.getLocation(ForgeDirection.DOWN);
|
||||
Block dirtBlock = farm.getBlock(dirtLoc);
|
||||
if((dirtBlock == Blocks.dirt || dirtBlock == Blocks.grass) && farm.hasHoe()) {
|
||||
farm.damageHoe(1, dirtLoc);
|
||||
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(),
|
||||
(Blocks.farmland.stepSound.getVolume() + 1.0F) / 2.0F, Blocks.farmland.stepSound.getPitch() * 0.8F);
|
||||
farm.damageHoe(1);
|
||||
farm.actionPerformed();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class StemFarmer extends SeedFarmer {
|
||||
}
|
||||
|
||||
}
|
||||
farm.damageMaxLootingItem();
|
||||
farm.damageMaxLootingItem(1, harvestCoord, farm.getBlock(harvestCoord));
|
||||
farm.actionPerformed();
|
||||
farm.getWorld().setBlockToAir(harvestCoord.x, harvestCoord.y, harvestCoord.z);
|
||||
} else {
|
||||
|
||||
@@ -81,7 +81,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
return result;
|
||||
}
|
||||
|
||||
public void damageMaxLootingItem() {
|
||||
public void damageMaxLootingItem(int damage, BlockCoord bc, Block block) {
|
||||
int maxLooting = -1;
|
||||
ItemStack toDamage = null;
|
||||
for (int i = minToolSlot; i <= maxToolSlot; i++) {
|
||||
@@ -94,7 +94,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
}
|
||||
}
|
||||
if(toDamage != null) {
|
||||
damageTool(toDamage.getItem().getClass(), 1);
|
||||
damageTool(toDamage.getItem().getClass(), block, bc, damage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,12 +119,12 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
}
|
||||
|
||||
|
||||
public void damageAxe() {
|
||||
damageTool(ItemAxe.class, 1);
|
||||
public void damageAxe(Block blk, BlockCoord bc) {
|
||||
damageTool(ItemAxe.class, blk, bc, 1);
|
||||
}
|
||||
|
||||
public void damageHoe(int i) {
|
||||
damageTool(ItemHoe.class, i);
|
||||
public void damageHoe(int i, BlockCoord bc) {
|
||||
damageTool(ItemHoe.class, null, bc, i);
|
||||
}
|
||||
|
||||
private boolean hasTool(Class<? extends Item> class1) {
|
||||
@@ -151,15 +151,16 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
|
||||
}
|
||||
|
||||
private void damageTool(Class<? extends Item> class1, int damage) {
|
||||
private void damageTool(Class<? extends Item> class1, Block blk, BlockCoord bc, int damage) {
|
||||
ItemStack tool = getTool(class1);
|
||||
if(tool == null) {
|
||||
return;
|
||||
}
|
||||
if(tool.getItem() instanceof ItemDarkSteelAxe) {
|
||||
((ItemDarkSteelAxe) tool.getItem()).applyBasicDamage(tool, damage);
|
||||
} else if(tool.getItem().isDamageable()) {
|
||||
tool.damageItem(damage, farmerJoe);
|
||||
|
||||
if(tool.getItem() instanceof ItemAxe) {
|
||||
tool.getItem().onBlockDestroyed(tool, worldObj, blk, bc.x, bc.y, bc.z, farmerJoe);
|
||||
} else if(tool.getItem() instanceof ItemHoe) {
|
||||
tool.getItem().onItemUse(tool, farmerJoe, worldObj, bc.x, bc.y, bc.z, 1, 0.5f, 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
if(tool.getItemDamage() >= tool.getMaxDamage()) {
|
||||
@@ -167,7 +168,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
|
||||
}
|
||||
}
|
||||
|
||||
private int getLooting(ItemStack stack) {
|
||||
private int getLooting(ItemStack stack) {
|
||||
return Math.max(
|
||||
EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, stack),
|
||||
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));
|
||||
|
||||
@@ -116,7 +116,7 @@ public class TreeFarmer implements IFarmerJoe {
|
||||
}
|
||||
farm.actionPerformed();
|
||||
if(isWood) {
|
||||
farm.damageAxe();
|
||||
farm.damageAxe(blk, coord);
|
||||
}
|
||||
farm.getWorldObj().setBlockToAir(coord.x, coord.y, coord.z);
|
||||
actualHarvests.add(coord);
|
||||
|
||||
Reference in new issue
Block a user