Search in sources :

Example 6 with Chunk

use of org.spongepowered.api.world.Chunk in project ClearMob by axle2005.

the class CommandClearChunks method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext arguments) {
    if (!Util.playerPermCheck(src, "clearmob.admin")) {
        return CommandResult.empty();
    } else {
        int unloaded = 0;
        for (World w : Sponge.getServer().getWorlds()) {
            for (Chunk c : w.getLoadedChunks()) {
                if (c.unloadChunk()) {
                    unloaded++;
                }
            }
        }
        src.sendMessage(Text.of(TextColors.AQUA, "[ClearMob] Unloaded: " + unloaded + " chunks"));
        return CommandResult.empty();
    }
}
Also used : World(org.spongepowered.api.world.World) Chunk(org.spongepowered.api.world.Chunk)

Example 7 with Chunk

use of org.spongepowered.api.world.Chunk in project SpongeCommon by SpongePowered.

the class MixinChunk method onLoadReturn.

@Inject(method = "onLoad", at = @At("RETURN"))
public void onLoadReturn(CallbackInfo ci) {
    for (Direction direction : CARDINAL_DIRECTIONS) {
        Vector3i neighborPosition = this.getPosition().add(direction.asBlockOffset());
        IMixinChunkProviderServer spongeChunkProvider = (IMixinChunkProviderServer) this.world.getChunkProvider();
        net.minecraft.world.chunk.Chunk neighbor = spongeChunkProvider.getLoadedChunkWithoutMarkingActive(neighborPosition.getX(), neighborPosition.getZ());
        if (neighbor != null) {
            int neighborIndex = directionToIndex(direction);
            int oppositeNeighborIndex = directionToIndex(direction.getOpposite());
            this.setNeighborChunk(neighborIndex, neighbor);
            ((IMixinChunk) neighbor).setNeighborChunk(oppositeNeighborIndex, (net.minecraft.world.chunk.Chunk) (Object) this);
        }
    }
    SpongeImpl.postEvent(SpongeEventFactory.createLoadChunkEvent(Sponge.getCauseStackManager().getCurrentCause(), (Chunk) this));
    if (!this.world.isRemote) {
        SpongeHooks.logChunkLoad(this.world, this.chunkPos);
    }
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Vector3i(com.flowpowered.math.vector.Vector3i) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(org.spongepowered.api.world.Chunk) Direction(org.spongepowered.api.util.Direction) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 8 with Chunk

use of org.spongepowered.api.world.Chunk in project SpongeCommon by SpongePowered.

the class MixinChunk method getNeighbor.

@Override
public Optional<Chunk> getNeighbor(Direction direction, boolean shouldLoad) {
    checkNotNull(direction, "direction");
    checkArgument(!direction.isSecondaryOrdinal(), "Secondary cardinal directions can't be used here");
    if (direction.isUpright() || direction == Direction.NONE) {
        return Optional.of(this);
    }
    int index = directionToIndex(direction);
    Direction secondary = getSecondaryDirection(direction);
    Chunk neighbor = null;
    neighbor = (Chunk) this.neighbors[index];
    if (neighbor == null && shouldLoad) {
        Vector3i neighborPosition = this.getPosition().add(getCardinalDirection(direction).asBlockOffset());
        Optional<Chunk> cardinal = this.getWorld().loadChunk(neighborPosition, true);
        if (cardinal.isPresent()) {
            neighbor = cardinal.get();
        }
    }
    if (neighbor != null && secondary != Direction.NONE) {
        return neighbor.getNeighbor(secondary, shouldLoad);
    }
    return Optional.ofNullable(neighbor);
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(org.spongepowered.api.world.Chunk) Direction(org.spongepowered.api.util.Direction)

Example 9 with Chunk

use of org.spongepowered.api.world.Chunk in project SpongeCommon by SpongePowered.

the class MixinChunk method onUnload.

@Inject(method = "onUnload", at = @At("RETURN"))
public void onUnload(CallbackInfo ci) {
    for (Direction direction : CARDINAL_DIRECTIONS) {
        Vector3i neighborPosition = this.getPosition().add(direction.asBlockOffset());
        IMixinChunkProviderServer spongeChunkProvider = (IMixinChunkProviderServer) this.world.getChunkProvider();
        net.minecraft.world.chunk.Chunk neighbor = spongeChunkProvider.getLoadedChunkWithoutMarkingActive(neighborPosition.getX(), neighborPosition.getZ());
        if (neighbor != null) {
            int neighborIndex = directionToIndex(direction);
            int oppositeNeighborIndex = directionToIndex(direction.getOpposite());
            this.setNeighborChunk(neighborIndex, null);
            ((IMixinChunk) neighbor).setNeighborChunk(oppositeNeighborIndex, null);
        }
    }
    if (!this.world.isRemote) {
        SpongeImpl.postEvent(SpongeEventFactory.createUnloadChunkEvent(Sponge.getCauseStackManager().getCurrentCause(), (Chunk) this));
        SpongeHooks.logChunkUnload(this.world, this.chunkPos);
    }
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Vector3i(com.flowpowered.math.vector.Vector3i) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(org.spongepowered.api.world.Chunk) Direction(org.spongepowered.api.util.Direction) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with Chunk

use of org.spongepowered.api.world.Chunk in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method callChunkUnloadEvent.

private static UnloadChunkEvent callChunkUnloadEvent(Event event) {
    UnloadChunkEvent spongeEvent = (UnloadChunkEvent) event;
    final net.minecraft.world.chunk.Chunk chunk = (net.minecraft.world.chunk.Chunk) spongeEvent.getTargetChunk();
    ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(new ChunkEvent.Unload(chunk), true);
    return spongeEvent;
}
Also used : IMixinEventBus(org.spongepowered.mod.interfaces.IMixinEventBus) ChunkEvent(net.minecraftforge.event.world.ChunkEvent) TargetChunkEvent(org.spongepowered.api.event.world.chunk.TargetChunkEvent) LoadChunkEvent(org.spongepowered.api.event.world.chunk.LoadChunkEvent) UnloadChunkEvent(org.spongepowered.api.event.world.chunk.UnloadChunkEvent) PopulateChunkEvent(net.minecraftforge.event.terraingen.PopulateChunkEvent) Chunk(org.spongepowered.api.world.Chunk) UnloadChunkEvent(org.spongepowered.api.event.world.chunk.UnloadChunkEvent)

Aggregations

Chunk (org.spongepowered.api.world.Chunk)12 Vector3i (com.flowpowered.math.vector.Vector3i)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 PopulateChunkEvent (net.minecraftforge.event.terraingen.PopulateChunkEvent)3 Direction (org.spongepowered.api.util.Direction)3 World (org.spongepowered.api.world.World)3 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)3 Lists (com.google.common.collect.Lists)2 Streams (com.google.common.collect.Streams)2 Random (java.util.Random)2 TreeMap (java.util.TreeMap)2 CatClearLag (me.time6628.clag.sponge.CatClearLag)2 LaggyChunksCommand (me.time6628.clag.sponge.commands.LaggyChunksCommand)2 ChunkEvent (net.minecraftforge.event.world.ChunkEvent)2 LanternWorld (org.lanternpowered.server.world.LanternWorld)2 CommandResult (org.spongepowered.api.command.CommandResult)2 CommandSource (org.spongepowered.api.command.CommandSource)2