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