Search in sources :

Example 76 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class ChunkMapMixin method impl$onSetUnloaded.

@Redirect(method = "lambda$scheduleUnload$10", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;unload(Lnet/minecraft/world/level/chunk/LevelChunk;)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;save(Lnet/minecraft/world/level/chunk/ChunkAccess;)Z")))
private void impl$onSetUnloaded(final ServerLevel level, final LevelChunk chunk) {
    final Vector3i chunkPos = new Vector3i(chunk.getPos().x, 0, chunk.getPos().z);
    if (ShouldFire.CHUNK_EVENT_UNLOAD_PRE) {
        final ChunkEvent.Unload event = SpongeEventFactory.createChunkEventUnloadPre(PhaseTracker.getInstance().currentCause(), (WorldChunk) chunk, chunkPos, (ResourceKey) (Object) this.level.dimension().location());
        SpongeCommon.post(event);
    }
    level.unload(chunk);
    for (final Direction dir : Constants.Chunk.CARDINAL_DIRECTIONS) {
        final Vector3i neighborPos = chunkPos.add(dir.asBlockOffset());
        final ChunkAccess neighbor = this.level.getChunk(neighborPos.x(), neighborPos.z(), ChunkStatus.EMPTY, false);
        if (neighbor instanceof LevelChunk) {
            final int index = DirectionUtil.directionToIndex(dir);
            final int oppositeIndex = DirectionUtil.directionToIndex(dir.opposite());
            ((LevelChunkBridge) chunk).bridge$setNeighborChunk(index, null);
            ((LevelChunkBridge) neighbor).bridge$setNeighborChunk(oppositeIndex, null);
        }
    }
    if (ShouldFire.CHUNK_EVENT_UNLOAD_POST) {
        final ChunkEvent.Unload event = SpongeEventFactory.createChunkEventUnloadPost(PhaseTracker.getInstance().currentCause(), chunkPos, (ResourceKey) (Object) this.level.dimension().location());
        SpongeCommon.post(event);
    }
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) Vector3i(org.spongepowered.math.vector.Vector3i) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) ChunkEvent(org.spongepowered.api.event.world.chunk.ChunkEvent) Direction(org.spongepowered.api.util.Direction) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 77 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class ChunkMapMixin method impl$useSerializationBehaviorForChunkSave.

@Redirect(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/storage/ChunkSerializer;write(Lnet/minecraft/server/level/ServerLevel;" + "Lnet/minecraft/world/level/chunk/ChunkAccess;)Lnet/minecraft/nbt/CompoundTag;"))
private CompoundTag impl$useSerializationBehaviorForChunkSave(final ServerLevel worldIn, final ChunkAccess chunkIn) {
    final PrimaryLevelDataBridge infoBridge = (PrimaryLevelDataBridge) this.level.getLevelData();
    final SerializationBehavior serializationBehavior = infoBridge.bridge$serializationBehavior().orElse(SerializationBehavior.AUTOMATIC);
    if (serializationBehavior == SerializationBehavior.AUTOMATIC || serializationBehavior == SerializationBehavior.MANUAL) {
        return ChunkSerializer.write(worldIn, chunkIn);
    }
    return null;
}
Also used : SerializationBehavior(org.spongepowered.api.world.SerializationBehavior) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 78 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class ChunkMapMixin method impl$useSerializationBehaviorForPOI.

@Redirect(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/village/poi/PoiManager;flush(Lnet/minecraft/world/level/ChunkPos;)V"))
private void impl$useSerializationBehaviorForPOI(final PoiManager pointOfInterestManager, final ChunkPos p_219112_1_) {
    final PrimaryLevelDataBridge infoBridge = (PrimaryLevelDataBridge) this.level.getLevelData();
    final SerializationBehavior serializationBehavior = infoBridge.bridge$serializationBehavior().orElse(SerializationBehavior.AUTOMATIC);
    if (serializationBehavior == SerializationBehavior.AUTOMATIC || serializationBehavior == SerializationBehavior.MANUAL) {
        pointOfInterestManager.flush(p_219112_1_);
    }
}
Also used : SerializationBehavior(org.spongepowered.api.world.SerializationBehavior) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 79 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class ServerEntityMixin method impl$sendHumanSpawnPacket.

/**
 * @author gabizou
 * @reason Because the entity spawn packet is just a lone packet, we have to actually
 * do some hackery to create the player list packet first, then the spawn packet,
 * then perform the remove packet.
 */
@Redirect(method = "sendPairingData", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V", ordinal = 0))
public void impl$sendHumanSpawnPacket(final Consumer<Packet<?>> consumer, final Object spawnPacket) {
    if (!(this.entity instanceof HumanEntity)) {
        consumer.accept((Packet<?>) spawnPacket);
        return;
    }
    final HumanEntity human = (HumanEntity) this.entity;
    // Adds the GameProfile to the client
    consumer.accept(human.createPlayerListPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER));
    // Actually spawn the human (a player)
    consumer.accept((Packet<?>) spawnPacket);
    // Remove from tab list
    final ClientboundPlayerInfoPacket removePacket = human.createPlayerListPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER);
    if (human.canRemoveFromListImmediately()) {
        consumer.accept(removePacket);
    } else {
        // TODO - find out if this is still needed.
        human.removeFromTabListDelayed(null, removePacket);
    }
}
Also used : HumanEntity(org.spongepowered.common.entity.living.human.HumanEntity) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 80 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class MinecraftMixin method impl$setWorldSettingsAdapter.

@Redirect(method = "loadWorldData", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/RegistryReadOps;create(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/RegistryAccess$RegistryHolder;)Lnet/minecraft/resources/RegistryReadOps;"))
private static RegistryReadOps impl$setWorldSettingsAdapter(final DynamicOps p_244335_0_, final ResourceManager p_244335_1_, final RegistryAccess.RegistryHolder p_244335_2_) {
    final RegistryReadOps worldSettingsAdapter = RegistryReadOps.create(p_244335_0_, p_244335_1_, p_244335_2_);
    BootstrapProperties.worldSettingsAdapter(worldSettingsAdapter);
    return worldSettingsAdapter;
}
Also used : RegistryReadOps(net.minecraft.resources.RegistryReadOps) 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