Search in sources :

Example 51 with Redirect

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;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) Player(net.minecraft.world.entity.player.Player) EnderDragon(net.minecraft.world.entity.boss.enderdragon.EnderDragon) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 52 with Redirect

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);
}
Also used : Path(java.nio.file.Path) Instant(java.time.Instant) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 53 with Redirect

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;
}
Also used : PrimaryLevelData(net.minecraft.world.level.storage.PrimaryLevelData) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 54 with Redirect

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);
}
Also used : PackRepository(net.minecraft.server.packs.repository.PackRepository) PluginRepositorySource(org.spongepowered.vanilla.server.packs.PluginRepositorySource) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 55 with Redirect

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();
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

Redirect (org.spongepowered.asm.mixin.injection.Redirect)165 CauseStackManager (org.spongepowered.api.event.CauseStackManager)25 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)15 ItemStack (net.minecraft.item.ItemStack)13 EffectTransactor (org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)13 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)12 TransactionalCaptureSupplier (org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier)11 ArrayList (java.util.ArrayList)9 ItemStack (net.minecraft.world.item.ItemStack)9 Nullable (javax.annotation.Nullable)8 Vector3d (com.flowpowered.math.vector.Vector3d)7 World (net.minecraft.world.World)7 ServerLocation (org.spongepowered.api.world.server.ServerLocation)7 DamageSourceBridge (org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge)7 IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)7 IBlockState (net.minecraft.block.state.IBlockState)6 Entity (net.minecraft.entity.Entity)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 ServerLevel (net.minecraft.server.level.ServerLevel)6 EntityItem (net.minecraft.entity.item.EntityItem)5