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);
}
}
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;
}
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_);
}
}
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);
}
}
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;
}
Aggregations