|
13 | 13 | import net.minecraft.entity.ai.RandomPositionGenerator;
|
14 | 14 | import net.minecraft.entity.ai.attributes.Attributes;
|
15 | 15 | import net.minecraft.entity.ai.goal.Goal;
|
| 16 | +import net.minecraft.entity.ai.goal.HurtByTargetGoal; |
16 | 17 | import net.minecraft.entity.ai.goal.SwimGoal;
|
17 | 18 | import net.minecraft.entity.player.PlayerEntity;
|
18 | 19 | import net.minecraft.item.BlockItem;
|
|
22 | 23 | import net.minecraft.network.datasync.DataSerializers;
|
23 | 24 | import net.minecraft.network.datasync.EntityDataManager;
|
24 | 25 | import net.minecraft.pathfinding.*;
|
| 26 | +import net.minecraft.potion.EffectInstance; |
| 27 | +import net.minecraft.potion.Effects; |
25 | 28 | import net.minecraft.tags.BlockTags;
|
26 | 29 | import net.minecraft.util.*;
|
27 | 30 | import net.minecraft.util.math.BlockPos;
|
@@ -72,6 +75,22 @@ public boolean attackEntityFrom(DamageSource source, float amount) {
|
72 | 75 | if(source.getTrueSource() == this.getAttackTarget() && this.attackSequenceTicks() > 0) {
|
73 | 76 | this.setAttackSequenceTicks(0);
|
74 | 77 | }
|
| 78 | + if (!world.isRemote()) { |
| 79 | + boolean isImmediate = source.getImmediateSource() instanceof PlayerEntity; |
| 80 | + PlayerEntity player = isImmediate ? (PlayerEntity) source.getImmediateSource() : (source.getTrueSource() instanceof PlayerEntity ? (PlayerEntity) source.getTrueSource() : null); |
| 81 | + if (player != null) { |
| 82 | + if (!this.isEntityAttackable(player)) { |
| 83 | + // retaliate attacks if you can't chase due to light |
| 84 | + if (!player.isCreative()) { |
| 85 | + player.addPotionEffect(new EffectInstance(Effects.BLINDNESS, 15 * 20, 1)); |
| 86 | + if (player.getDistance(this) < 3) |
| 87 | + player.attackEntityFrom(HIDEBEHIND, 1F); |
| 88 | + } |
| 89 | + HideFromTargetGoal.doTreeTick(this); |
| 90 | + return false; |
| 91 | + } |
| 92 | + } |
| 93 | + } |
75 | 94 | return super.attackEntityFrom(source, amount);
|
76 | 95 | }
|
77 | 96 |
|
@@ -330,7 +349,11 @@ public void startExecuting() {
|
330 | 349 |
|
331 | 350 | @Override
|
332 | 351 | public void tick() {
|
333 |
| - this.hidebehind.getNavigator().clearPath(); |
| 352 | + doTreeTick(hidebehind); |
| 353 | + } |
| 354 | + |
| 355 | + public static void doTreeTick(EntityHidebehind hidebehind) { |
| 356 | + hidebehind.getNavigator().clearPath(); |
334 | 357 | boolean nearTree = false;
|
335 | 358 | for(Direction dir : Direction.values()) {
|
336 | 359 | if(!nearTree) {
|
@@ -385,6 +408,11 @@ protected void registerData() {
|
385 | 408 | this.dataManager.register(ATTACK_SEQUENCE_TICKS, 0);
|
386 | 409 | }
|
387 | 410 |
|
| 411 | + @Override |
| 412 | + public boolean canDespawn(double range) { |
| 413 | + return world.isDaytime() && super.canDespawn(range); |
| 414 | + } |
| 415 | + |
388 | 416 | @Override
|
389 | 417 | protected PathNavigator createNavigator(World world) {
|
390 | 418 | return new HidebehindGroundNavigator(this, world);
|
|
0 commit comments