player entity value may become invalid due to respawns. This not only fixes #633, but also other cases where player reference is used over time while player respawns and its instance is recycled.
This commit is contained in:
1 parent
f0a52fc751
commit
d6eb53b6ce
4 files changed
+41
-9
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.ServerPlayerEntityInterface;
|
||||
import net.minecraft.server.PlayerManager;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -17,4 +18,11 @@ public class PlayerManager_scarpetEventsMixin
|
||||
{
|
||||
PLAYER_RESPAWNS.onPlayerEvent(player);
|
||||
}
|
||||
|
||||
@Inject(method = "respawnPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;onSpawn()V"))
|
||||
private void invalidatePreviousInstance(ServerPlayerEntity player, boolean alive, CallbackInfoReturnable<ServerPlayerEntity> cir)
|
||||
{
|
||||
((ServerPlayerEntityInterface)player).invalidateEntityObjectReference();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.EntityInterface;
|
||||
import carpet.fakes.ServerPlayerEntityInterface;
|
||||
import carpet.script.EntityEventsGroup;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -28,8 +29,11 @@ import static carpet.script.CarpetEventServer.Event.PLAYER_FINISHED_USING_ITEM;
|
||||
import static carpet.script.CarpetEventServer.Event.STATISTICS;
|
||||
|
||||
@Mixin(ServerPlayerEntity.class)
|
||||
public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity
|
||||
public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity implements ServerPlayerEntityInterface
|
||||
{
|
||||
// to denote if the player reference is valid
|
||||
|
||||
private boolean isInvalidReference = false;
|
||||
|
||||
public ServerPlayerEntity_scarpetEventMixin(World world, BlockPos blockPos, float f, GameProfile gameProfile)
|
||||
{
|
||||
@@ -109,6 +113,17 @@ public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity
|
||||
}
|
||||
PLAYER_CHANGES_DIMENSION.onDimensionChange(player, previousLocation, to, previousDimension, destination.getRegistryKey());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void invalidateEntityObjectReference()
|
||||
{
|
||||
isInvalidReference = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvalidEntityObject()
|
||||
{
|
||||
return isInvalidReference;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user