|
98 | 98 | import org.spongepowered.common.SpongeCommon; |
99 | 99 | import org.spongepowered.common.accessor.server.level.ChunkMapAccessor; |
100 | 100 | import org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor; |
101 | | -import org.spongepowered.common.accessor.world.entity.EntityAccessor; |
102 | 101 | import org.spongepowered.common.accessor.world.entity.PortalProcessorAccessor; |
103 | 102 | import org.spongepowered.common.bridge.commands.CommandSourceProviderBridge; |
104 | 103 | import org.spongepowered.common.bridge.data.DataCompoundHolder; |
@@ -182,6 +181,7 @@ public abstract class EntityMixin implements EntityBridge, PlatformEntityBridge, |
182 | 181 | @Shadow public abstract boolean shadow$onGround(); |
183 | 182 | @Shadow @Nullable protected abstract String shadow$getEncodeId(); |
184 | 183 | @Shadow @javax.annotation.Nullable public PortalProcessor portalProcess; |
| 184 | + @Shadow public abstract void shadow$stopRiding(); |
185 | 185 | // @formatter:on |
186 | 186 |
|
187 | 187 | private boolean impl$isConstructing = true; |
@@ -306,23 +306,15 @@ public abstract class EntityMixin implements EntityBridge, PlatformEntityBridge, |
306 | 306 |
|
307 | 307 | @Override |
308 | 308 | public boolean bridge$dismountRidingEntity(final DismountType type) { |
309 | | - if (!this.shadow$level().isClientSide && ShouldFire.RIDE_ENTITY_EVENT_DISMOUNT) { |
310 | | - try (final CauseStackManager.StackFrame frame = PhaseTracker.getInstance().pushCauseFrame()) { |
311 | | - frame.pushCause(this); |
312 | | - frame.addContext(EventContextKeys.DISMOUNT_TYPE, type); |
313 | | - if (SpongeCommon.post(SpongeEventFactory. |
314 | | - createRideEntityEventDismount(frame.currentCause(), (org.spongepowered.api.entity.Entity) this.shadow$getVehicle()))) { |
315 | | - return false; |
316 | | - } |
317 | | - } |
318 | | - } |
| 309 | + final Entity vehicle = this.shadow$getVehicle(); |
| 310 | + |
| 311 | + try (final CauseStackManager.StackFrame frame = PhaseTracker.getInstance().pushCauseFrame()) { |
| 312 | + frame.addContext(EventContextKeys.DISMOUNT_TYPE, type); |
319 | 313 |
|
320 | | - final Entity tempEntity = this.shadow$getVehicle(); |
321 | | - if (tempEntity != null) { |
322 | | - this.vehicle = null; |
323 | | - ((EntityAccessor) tempEntity).invoker$removePassenger((Entity) (Object) this); |
| 314 | + this.shadow$stopRiding(); |
324 | 315 | } |
325 | | - return true; |
| 316 | + |
| 317 | + return vehicle != this.shadow$getVehicle(); |
326 | 318 | } |
327 | 319 |
|
328 | 320 | @Override |
@@ -616,18 +608,26 @@ public Entity changeDimension(final DimensionTransition transition) { |
616 | 608 | } |
617 | 609 | } |
618 | 610 |
|
619 | | - /** |
620 | | - * @author rexbut - December 16th, 2016 |
621 | | - * @reason - adjusted to support {@link DismountTypes} |
622 | | - */ |
623 | | - @Overwrite |
624 | | - public void stopRiding() { |
| 611 | + @Inject(method = "removeVehicle", |
| 612 | + at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/Entity;vehicle:Lnet/minecraft/world/entity/Entity;", opcode = Opcodes.PUTFIELD), cancellable = true) |
| 613 | + private void impl$onRemoveVehicle(final CallbackInfo ci) { |
625 | 614 | final Entity vehicle = this.shadow$getVehicle(); |
626 | 615 | if (vehicle != null) { |
627 | | - if (vehicle.isRemoved()) { |
628 | | - this.bridge$dismountRidingEntity(DismountTypes.DEATH.get()); |
629 | | - } else { |
630 | | - this.bridge$dismountRidingEntity(DismountTypes.PLAYER.get()); |
| 616 | + if (this.shadow$level().isClientSide || !ShouldFire.RIDE_ENTITY_EVENT_DISMOUNT) { |
| 617 | + return; |
| 618 | + } |
| 619 | + |
| 620 | + try (final CauseStackManager.StackFrame frame = PhaseTracker.getInstance().pushCauseFrame()) { |
| 621 | + frame.pushCause(this); |
| 622 | + if (!frame.currentContext().containsKey(EventContextKeys.DISMOUNT_TYPE)) { |
| 623 | + frame.addContext(EventContextKeys.DISMOUNT_TYPE, vehicle.isRemoved() |
| 624 | + ? DismountTypes.DEATH.get() |
| 625 | + : DismountTypes.PLAYER.get()); |
| 626 | + } |
| 627 | + if (SpongeCommon.post(SpongeEventFactory. |
| 628 | + createRideEntityEventDismount(frame.currentCause(), (org.spongepowered.api.entity.Entity) this.shadow$getVehicle()))) { |
| 629 | + ci.cancel(); |
| 630 | + } |
631 | 631 | } |
632 | 632 | } |
633 | 633 | } |
|
0 commit comments