Skip to content

Commit 1125300

Browse files
committed
Check axe harvest level for Ent damage
Supports any axe-like tools
1 parent bb1604b commit 1125300

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/main/java/drzhark/mocreatures/entity/neutral/MoCEntityEnt.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import net.minecraft.init.Blocks;
2525
import net.minecraft.init.Items;
2626
import net.minecraft.item.Item;
27-
import net.minecraft.item.ItemAxe;
2827
import net.minecraft.item.ItemStack;
2928
import net.minecraft.pathfinding.Path;
3029
import net.minecraft.util.DamageSource;
@@ -89,15 +88,14 @@ protected int getExperiencePoints(EntityPlayer player) {
8988

9089
@Override
9190
public boolean attackEntityFrom(DamageSource damagesource, float i) {
92-
if (damagesource.getTrueSource() != null && damagesource.getTrueSource() instanceof EntityPlayer) {
93-
EntityPlayer ep = (EntityPlayer) damagesource.getTrueSource();
94-
ItemStack currentItem = ep.inventory.getCurrentItem();
95-
Item itemheld = currentItem.getItem();
96-
if (itemheld instanceof ItemAxe) {
91+
if (damagesource.getTrueSource() instanceof EntityPlayer) {
92+
EntityPlayer player = (EntityPlayer) damagesource.getTrueSource();
93+
ItemStack heldStack = player.inventory.getCurrentItem();
94+
Item heldItem = heldStack.getItem();
95+
if (heldItem.getHarvestLevel(heldStack, "axe", player, null) >= 0) {
9796
this.world.getDifficulty();
9897
if (super.shouldAttackPlayers()) {
99-
setAttackTarget(ep);
100-
98+
setAttackTarget(player);
10199
}
102100
return super.attackEntityFrom(damagesource, i);
103101
}
@@ -191,9 +189,7 @@ private void plantOnFertileGround() {
191189
Block block = Blocks.GRASS;
192190
BlockEvent.BreakEvent event = null;
193191
if (!this.world.isRemote) {
194-
event =
195-
new BlockEvent.BreakEvent(this.world, pos, block.getDefaultState(), FakePlayerFactory.get((WorldServer) this.world,
196-
MoCreatures.MOCFAKEPLAYER));
192+
event = new BlockEvent.BreakEvent(this.world, pos, block.getDefaultState(), FakePlayerFactory.get((WorldServer) this.world, MoCreatures.MOCFAKEPLAYER));
197193
}
198194
if (event != null && !event.isCanceled()) {
199195
this.world.setBlockState(pos.down(), block.getDefaultState(), 3);

0 commit comments

Comments
 (0)