|
24 | 24 | */
|
25 | 25 | package org.spongepowered.common.mixin.core.world.entity.ai.goal;
|
26 | 26 |
|
27 |
| -import net.minecraft.world.entity.Entity; |
28 | 27 | import net.minecraft.world.entity.ai.goal.RunAroundLikeCrazyGoal;
|
29 | 28 | import net.minecraft.world.entity.animal.horse.AbstractHorse;
|
30 |
| -import net.minecraft.world.entity.player.Player; |
31 | 29 | import org.spongepowered.api.entity.living.animal.horse.HorseLike;
|
32 | 30 | import org.spongepowered.api.event.CauseStackManager;
|
33 | 31 | import org.spongepowered.api.event.SpongeEventFactory;
|
34 | 32 | import org.spongepowered.api.event.cause.entity.DismountTypes;
|
35 | 33 | import org.spongepowered.asm.mixin.Final;
|
36 | 34 | import org.spongepowered.asm.mixin.Mixin;
|
37 |
| -import org.spongepowered.asm.mixin.Mutable; |
38 |
| -import org.spongepowered.asm.mixin.Overwrite; |
39 | 35 | import org.spongepowered.asm.mixin.Shadow;
|
| 36 | +import org.spongepowered.asm.mixin.injection.At; |
| 37 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 38 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
40 | 39 | import org.spongepowered.common.SpongeCommon;
|
41 | 40 | import org.spongepowered.common.bridge.world.entity.EntityBridge;
|
42 | 41 | import org.spongepowered.common.event.tracking.PhaseTracker;
|
|
45 | 44 | public abstract class RunAroundLikeCrazyGoalMixin extends GoalMixin {
|
46 | 45 |
|
47 | 46 | // @formatter:off
|
48 |
| - @Shadow @Final @Mutable private AbstractHorse horse; |
| 47 | + @Shadow @Final private AbstractHorse horse; |
49 | 48 | // @formatter:on
|
50 | 49 |
|
51 |
| - /** |
52 |
| - * @author rexbut - December 16th, 2016 |
53 |
| - * @author i509VCB - February 18th, 2020 - 1.14.4 |
54 |
| - * |
55 |
| - * @reason - adjusted to support {@link DismountTypes} |
56 |
| - */ |
57 |
| - @Overwrite |
58 |
| - public void tick() { |
59 |
| - if (!this.horse.isTamed() && this.horse.getRandom().nextInt(50) == 0) { |
60 |
| - Entity entity = this.horse.getPassengers().get(0); |
61 |
| - |
62 |
| - if (entity == null) { |
63 |
| - return; |
64 |
| - } |
65 |
| - |
66 |
| - if (entity instanceof Player) { |
67 |
| - int i = this.horse.getTemper(); |
68 |
| - int j = this.horse.getMaxTemper(); |
69 |
| - |
70 |
| - if (j > 0 && this.horse.getRandom().nextInt(j) < i) { |
71 |
| - // Sponge start - Fire Tame Entity event |
72 |
| - try (CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) { |
73 |
| - frame.pushCause(entity); |
74 |
| - if (SpongeCommon.post(SpongeEventFactory.createTameEntityEvent(frame.currentCause(), (HorseLike) this.horse))) { |
75 |
| - return; |
76 |
| - } |
77 |
| - } |
78 |
| - // Sponge end |
79 |
| - this.horse.tameWithName((Player)entity); |
80 |
| - return; |
81 |
| - } |
82 |
| - |
83 |
| - this.horse.modifyTemper(5); |
| 50 | + @Inject( |
| 51 | + method = "tick", |
| 52 | + at = @At( |
| 53 | + value = "INVOKE", |
| 54 | + target = "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;tameWithName(Lnet/minecraft/world/entity/player/Player;)Z" |
| 55 | + ), |
| 56 | + cancellable = true |
| 57 | + ) |
| 58 | + private void impl$throwTameEntityEvent(final CallbackInfo ci) { |
| 59 | + try (CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) { |
| 60 | + frame.pushCause(this.horse.getFirstPassenger()); |
| 61 | + if (SpongeCommon.post(SpongeEventFactory.createTameEntityEvent(frame.currentCause(), (HorseLike) this.horse))) { |
| 62 | + ci.cancel(); |
84 | 63 | }
|
| 64 | + } |
| 65 | + } |
85 | 66 |
|
86 |
| - // Sponge start - Throw an event before calling entity states |
87 |
| - // this.horseHost.ejectPassengers(); // Vanilla |
88 |
| - if (((EntityBridge) this.horse).bridge$removePassengers(DismountTypes.DERAIL.get())) { |
89 |
| - // Sponge end |
90 |
| - this.horse.makeMad(); |
91 |
| - this.horse.level().broadcastEntityEvent(this.horse, (byte)6); |
92 |
| - } |
| 67 | + @Inject( |
| 68 | + method = "tick", |
| 69 | + at = @At( |
| 70 | + value = "INVOKE", |
| 71 | + target = "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;ejectPassengers()V" |
| 72 | + ), |
| 73 | + cancellable = true |
| 74 | + ) |
| 75 | + private void impl$handleDismountTypes(final CallbackInfo ci) { |
| 76 | + if (((EntityBridge) this.horse).bridge$removePassengers(DismountTypes.DERAIL.get())) { |
| 77 | + this.horse.makeMad(); |
| 78 | + this.horse.level().broadcastEntityEvent(this.horse, (byte)6); |
93 | 79 | }
|
| 80 | + |
| 81 | + ci.cancel(); |
94 | 82 | }
|
95 | 83 | }
|
0 commit comments