use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.
the class MixinWorldEntitySpawner method getRandomChunkPosition.
/**
* @author aikar - February 20th, 2017 - Optimizes light level check.
* @author blood - February 20th, 2017 - Avoids checking unloaded chunks and chunks with pending light updates.
*
* @reason Avoids checking unloaded chunks and chunks with pending light updates.
*/
@Overwrite
private static BlockPos getRandomChunkPosition(World worldIn, int x, int z) {
// Sponge start
final Chunk chunk = ((IMixinChunkProviderServer) worldIn.getChunkProvider()).getLoadedChunkWithoutMarkingActive(x, z);
if (chunk == null || (chunk.unloadQueued && !((IMixinChunk) chunk).isPersistedChunk())) {
// Don't attempt to spawn in an unloaded chunk
return null;
}
// Sponge end
int i = x * 16 + worldIn.rand.nextInt(16);
int j = z * 16 + worldIn.rand.nextInt(16);
int k = MathHelper.roundUp(chunk.getHeight(new BlockPos(i, 0, j)) + 1, 16);
int l = worldIn.rand.nextInt(k > 0 ? k : chunk.getTopFilledSegment() + 16 - 1);
return new BlockPos(i, l, j);
}
use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.
the class MixinWorldServer method neighborChanged.
/**
* @author gabizou - March 12th, 2016
*
* Technically an overwrite to properly track on *server* worlds.
*/
@Override
public void neighborChanged(BlockPos pos, Block blockIn, BlockPos otherPos) {
// notifyBlockOfStateChange
final Chunk chunk = ((IMixinChunkProviderServer) this.getChunkProvider()).getLoadedChunkWithoutMarkingActive(otherPos.getX() >> 4, otherPos.getZ() >> 4);
// Don't let neighbor updates trigger a chunk load ever
if (chunk == null) {
return;
}
PhaseTracker.getInstance().notifyBlockOfStateChange(this, pos, blockIn, otherPos);
}
use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.
the class MixinWorldServer method notifyNeighborsOfStateExcept.
/**
* @author gabizou - March 12th, 2016
*
* Technically an overwrite to properly track on *server* worlds.
*/
@Override
public void notifyNeighborsOfStateExcept(BlockPos pos, Block blockType, EnumFacing skipSide) {
if (!isValid(pos)) {
return;
}
final Chunk chunk = ((IMixinChunkProviderServer) this.getChunkProvider()).getLoadedChunkWithoutMarkingActive(pos.getX() >> 4, pos.getZ() >> 4);
// Don't let neighbor updates trigger a chunk load ever
if (chunk == null) {
return;
}
EnumSet<EnumFacing> directions = EnumSet.copyOf(NOTIFY_DIRECTIONS);
directions.remove(skipSide);
final NotifyNeighborBlockEvent event = SpongeCommonEventFactory.callNotifyNeighborEvent(this, pos, directions);
if (event == null || !event.isCancelled()) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
for (EnumFacing facing : EnumFacing.values()) {
if (event != null) {
final Direction direction = DirectionFacingProvider.getInstance().getKey(facing).get();
if (!event.getNeighbors().keySet().contains(direction)) {
continue;
}
}
phaseTracker.notifyBlockOfStateChange(this, pos.offset(facing), blockType, pos);
}
}
}
use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.
the class MixinEntityMob method isValidLightLevel.
/**
* @author aikar - February 20th, 2017 - Optimizes light level check.
* @author blood - February 20th, 2017 - Avoids checking unloaded chunks and chunks with pending light updates.
*
* @reason Avoids checking unloaded chunks and chunks with pending light updates.
*
* @return Whether current position has a valid light level for spawning
*/
@Overwrite
protected boolean isValidLightLevel() {
final BlockPos blockpos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ);
final Chunk chunk = ((IMixinChunkProviderServer) this.world.getChunkProvider()).getLoadedChunkWithoutMarkingActive(blockpos.getX() >> 4, blockpos.getZ() >> 4);
if (chunk == null || chunk.unloadQueued) {
return false;
}
if (this.world.getLightFor(EnumSkyBlock.SKY, blockpos) > this.rand.nextInt(32)) {
return false;
} else {
// int i = this.worldObj.getLightFromNeighbors(blockpos);
// Sponge
boolean passes;
if (this.world.isThundering()) {
int j = this.world.getSkylightSubtracted();
;
this.world.setSkylightSubtracted(10);
passes = !((IMixinWorldServer) this.world).isLightLevel(chunk, blockpos, this.rand.nextInt(9));
this.world.setSkylightSubtracted(j);
} else {
passes = !((IMixinWorldServer) this.world).isLightLevel(chunk, blockpos, this.rand.nextInt(9));
}
return passes;
}
}
use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.
the class WorldManager method createWorldFromProperties.
private static WorldServer createWorldFromProperties(int dimensionId, ISaveHandler saveHandler, WorldInfo worldInfo, @Nullable WorldSettings worldSettings) {
final MinecraftServer server = SpongeImpl.getServer();
final WorldServer worldServer = new WorldServer(server, saveHandler, worldInfo, dimensionId, server.profiler);
worldServer.init();
// WorldSettings is only non-null here if this is a newly generated WorldInfo and therefore we need to initialize to calculate spawn.
if (worldSettings != null) {
worldServer.initialize(worldSettings);
}
worldServer.addEventListener(new ServerWorldEventHandler(server, worldServer));
// This code changes from Mojang's to account for per-world API-set GameModes.
if (!server.isSinglePlayer() && worldServer.getWorldInfo().getGameType().equals(GameType.NOT_SET)) {
worldServer.getWorldInfo().setGameType(server.getGameType());
}
worldByDimensionId.put(dimensionId, worldServer);
weakWorldByWorld.put(worldServer, worldServer);
((IMixinMinecraftServer) SpongeImpl.getServer()).putWorldTickTimes(dimensionId, new long[100]);
((IMixinChunkProviderServer) worldServer.getChunkProvider()).setForceChunkRequests(true);
WorldManager.reorderWorldsVanillaFirst();
SpongeImpl.postEvent(SpongeEventFactory.createLoadWorldEvent(Sponge.getCauseStackManager().getCurrentCause(), (org.spongepowered.api.world.World) worldServer));
((IMixinMinecraftServer) server).prepareSpawnArea(worldServer);
((IMixinChunkProviderServer) worldServer.getChunkProvider()).setForceChunkRequests(false);
return worldServer;
}
Aggregations