Skip to content

Commit

Permalink
Fix ServerEntityWorldChangeEvents.AFTER_ENTITY_CHANGE_WORLD being cal…
Browse files Browse the repository at this point in the history
…led for entities teleporting within the same world. (#4391)

(cherry picked from commit bcdf965)
  • Loading branch information
modmuss50 committed Jan 21, 2025
1 parent 8212661 commit 1934821
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package net.fabricmc.fabric.mixin.entity.event;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -34,13 +34,15 @@ abstract class EntityMixin {
@Shadow
private World world;

@Inject(method = "teleportTo", at = @At("RETURN"))
private void afterWorldChanged(TeleportTarget target, CallbackInfoReturnable<Entity> cir) {
@WrapOperation(method = "teleportTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;teleportCrossDimension(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/TeleportTarget;)Lnet/minecraft/entity/Entity;"))
private Entity afterWorldChanged(Entity instance, ServerWorld targetWorld, TeleportTarget teleportTarget, Operation<Entity> original) {
// Ret will only have an entity if the teleport worked (entity not removed, teleportTarget was valid, entity was successfully created)
Entity ret = cir.getReturnValue();
Entity ret = original.call(instance, targetWorld, teleportTarget);

if (ret != null) {
ServerEntityWorldChangeEvents.AFTER_ENTITY_CHANGE_WORLD.invoker().afterChangeWorld((Entity) (Object) this, ret, (ServerWorld) this.world, (ServerWorld) ret.getWorld());
}

return ret;
}
}

0 comments on commit 1934821

Please sign in to comment.