use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class LivingEntityMixin_EntityCollision method collisions$pushEntities.
// This injection allows maxEntityCramming to be applied first before checking for max collisions
@Redirect(method = "pushEntities", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", remap = false))
private int collisions$pushEntities(final List<Entity> list) {
for (final Entity entity : list) {
// ignore players and entities with parts (ex. EnderDragon)
if (this.shadow$getCommandSenderWorld().isClientSide() || entity == null || entity instanceof Player || entity instanceof EnderDragon) {
continue;
}
if (this.collision$requiresCollisionsCacheRefresh()) {
this.collision$initializeCollisionState(this.shadow$getCommandSenderWorld());
this.collision$requiresCollisionsCacheRefresh(false);
}
if (this.collision$getMaxCollisions() >= 0 && list.size() >= this.collision$getMaxCollisions()) {
// Don't process any more collisions
break;
}
this.shadow$doPush(entity);
}
// We always return '0' to prevent the original loop from running.
return 0;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class PlayerDataStorageMixin method impl$readSpongePlayerData.
@Redirect(method = "load", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;load(Lnet/minecraft/nbt/CompoundTag;)V"))
private void impl$readSpongePlayerData(final Player playerEntity, final CompoundTag compound) throws IOException {
playerEntity.load(compound);
final Path file = new File(this.playerDir, playerEntity.getStringUUID() + ".dat").toPath();
final Instant creationTime = Files.exists(file) ? Files.readAttributes(file, BasicFileAttributes.class).creationTime().toInstant() : null;
((SpongeServer) SpongeCommon.server()).getPlayerDataManager().readPlayerData(compound, null, creationTime);
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class LevelStorageSourceMixin_Vanilla method impl$readSpongeLevelData.
@Redirect(method = "lambda$getLevelData$4", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/LevelSettings;parse(Lcom/mojang/serialization/Dynamic;Lnet/minecraft/world/level/DataPackConfig;)Lnet/minecraft/world/level/LevelSettings;"), to = @At(value = "RETURN")), at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;parse(Lcom/mojang/serialization/Dynamic;Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/storage/LevelVersion;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)Lnet/minecraft/world/level/storage/PrimaryLevelData;"))
private static PrimaryLevelData impl$readSpongeLevelData(final Dynamic<Tag> p_237369_0_, final DataFixer p_237369_1_, final int p_237369_2_, final CompoundTag p_237369_3_, final LevelSettings p_237369_4_, final LevelVersion p_237369_5_, final WorldGenSettings p_237369_6_, final Lifecycle p_237369_7_) {
final PrimaryLevelData levelData = PrimaryLevelData.parse(p_237369_0_, p_237369_1_, p_237369_2_, p_237369_3_, p_237369_4_, p_237369_5_, p_237369_6_, p_237369_7_);
((PrimaryLevelDataBridge) levelData).bridge$readSpongeLevelData(LevelStorageSourceMixin_Vanilla.impl$spongeLevelData);
LevelStorageSourceMixin_Vanilla.impl$spongeLevelData = null;
return levelData;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class PackRepositoryMixin_Vanilla method vanilla$addPluginRepository.
@SuppressWarnings("rawtypes")
@Redirect(method = "<init>*", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableSet;copyOf([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;"))
private ImmutableSet vanilla$addPluginRepository(final Object[] elements) {
final Object[] copied = Arrays.copyOf(elements, elements.length + 1);
copied[elements.length] = new PluginRepositorySource((PackRepository) (Object) this);
return ImmutableSet.copyOf(copied);
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class ChunkMapMixin_Tracker method tracker$startLoad.
@Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/LevelChunk;runPostLoad()V"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/LevelChunk;setFullStatus(Ljava/util/function/Supplier;)V"), to = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addAllPendingBlockEntities(Ljava/util/Collection;)V")))
private void tracker$startLoad(final LevelChunk chunk) {
chunk.runPostLoad();
final boolean isFake = ((LevelBridge) chunk.getLevel()).bridge$isFake();
if (isFake) {
return;
}
if (!PhaseTracker.SERVER.onSidedThread()) {
new PrettyPrinter(60).add("Illegal Async Chunk Load").centre().hr().addWrapped("Sponge relies on knowing when chunks are being loaded as chunks add entities" + " to the parented world for management. These operations are generally not" + " threadsafe and shouldn't be considered a \"Sponge bug \". Adding/removing" + " entities from another thread to the world is never ok.").add().add(" %s : %s", "Chunk Pos", chunk.getPos().toString()).add().add(new Exception("Async Chunk Load Detected")).log(SpongeCommon.logger(), Level.ERROR);
return;
}
if (PhaseTracker.getInstance().getCurrentState() == GenerationPhase.State.CHUNK_REGENERATING_LOAD_EXISTING) {
return;
}
GenerationPhase.State.CHUNK_LOADING.createPhaseContext(PhaseTracker.getInstance()).source(chunk).world((ServerLevel) chunk.getLevel()).chunk(chunk).buildAndSwitch();
}
Aggregations