use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.
the class SpongeChunkGenerator method generateChunk.
@Override
public Chunk generateChunk(int chunkX, int chunkZ) {
this.rand.setSeed(chunkX * 341873128712L + chunkZ * 132897987541L);
this.cachedBiomes.reuse(new Vector3i(chunkX * 16, 0, chunkZ * 16));
this.biomeGenerator.generateBiomes(this.cachedBiomes);
ImmutableBiomeVolume biomeBuffer = this.cachedBiomes.getImmutableBiomeCopy();
// Generate base terrain
ChunkPrimer chunkprimer = new ChunkPrimer();
MutableBlockVolume blockBuffer = new ChunkPrimerBuffer(chunkprimer, chunkX, chunkZ);
this.baseGenerator.populate((org.spongepowered.api.world.World) this.world, blockBuffer, biomeBuffer);
if (!(this.baseGenerator instanceof SpongeGenerationPopulator)) {
replaceBiomeBlocks(this.world, this.rand, chunkX, chunkZ, chunkprimer, biomeBuffer);
}
// Apply the generator populators to complete the blockBuffer
for (GenerationPopulator populator : this.genpop) {
populator.populate((org.spongepowered.api.world.World) this.world, blockBuffer, biomeBuffer);
}
// Get unique biomes to determine what generator populators to run
List<BiomeType> uniqueBiomes = Lists.newArrayList();
BiomeType biome;
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
biome = this.cachedBiomes.getBiome(chunkX * 16 + x, 0, chunkZ * 16 + z);
if (!uniqueBiomes.contains(biome)) {
uniqueBiomes.add(biome);
}
}
}
// run our generator populators
for (BiomeType type : uniqueBiomes) {
BiomeGenerationSettings settings = getBiomeSettings(type);
for (GenerationPopulator populator : settings.getGenerationPopulators()) {
populator.populate((org.spongepowered.api.world.World) this.world, blockBuffer, biomeBuffer);
}
}
// Assemble chunk
Chunk chunk;
if (this.baseGenerator instanceof SpongeGenerationPopulator && ((SpongeGenerationPopulator) this.baseGenerator).getCachedChunk() != null) {
chunk = ((SpongeGenerationPopulator) this.baseGenerator).getCachedChunk();
((IMixinChunk) chunk).fill(chunkprimer);
} else {
chunk = new Chunk(this.world, chunkprimer, chunkX, chunkZ);
this.cachedBiomes.fill(chunk.getBiomeArray());
}
chunk.generateSkylightMap();
return chunk;
}
use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.
the class MixinChunk_Async_Lighting method onRelightChecksGetBlockState.
@Redirect(method = "enqueueRelightChecks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;"))
private IBlockState onRelightChecksGetBlockState(World world, BlockPos pos) {
Chunk chunk = ((IMixinChunkProviderServer) world.getChunkProvider()).getLoadedChunkWithoutMarkingActive(pos.getX() >> 4, pos.getZ() >> 4);
final IMixinChunk spongeChunk = (IMixinChunk) chunk;
if (chunk == null || chunk.unloadQueued || !spongeChunk.areNeighborsLoaded()) {
return Blocks.AIR.getDefaultState();
}
return chunk.getBlockState(pos);
}
use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.
the class MixinChunk_Async_Lighting method getSurroundingChunks.
/**
* Gets surrounding chunks thread-safe.
*
* @return The list of surrounding chunks, empty list if not loaded
*/
private List<Chunk> getSurroundingChunks() {
if (!this.areNeighborsLoaded()) {
return EMPTY_LIST;
}
// add diagonal chunks
final Chunk southEastChunk = ((IMixinChunk) this.getNeighborChunk(0)).getNeighborChunk(2);
if (southEastChunk == null) {
return EMPTY_LIST;
}
final Chunk southWestChunk = ((IMixinChunk) this.getNeighborChunk(0)).getNeighborChunk(3);
if (southWestChunk == null) {
return EMPTY_LIST;
}
final Chunk northEastChunk = ((IMixinChunk) this.getNeighborChunk(1)).getNeighborChunk(2);
if (northEastChunk == null) {
return EMPTY_LIST;
}
final Chunk northWestChunk = ((IMixinChunk) this.getNeighborChunk(1)).getNeighborChunk(3);
if (northWestChunk == null) {
return EMPTY_LIST;
}
List<Chunk> chunkList = new ArrayList<>();
chunkList = this.getNeighbors();
chunkList.add(southEastChunk);
chunkList.add(southWestChunk);
chunkList.add(northEastChunk);
chunkList.add(northWestChunk);
return chunkList;
}
use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.
the class MixinWorldServer_Async_Lighting method updateLightAsync.
@Override
public boolean updateLightAsync(EnumSkyBlock lightType, BlockPos pos, @Nullable Chunk currentChunk) {
if (this.getMinecraftServer().isServerStopped() || this.lightExecutorService.isShutdown()) {
return false;
}
if (currentChunk == null) {
currentChunk = ((IMixinChunkProviderServer) this.chunkProvider).getLoadedChunkWithoutMarkingActive(pos.getX() >> 4, pos.getZ() >> 4);
}
final IMixinChunk spongeChunk = (IMixinChunk) currentChunk;
if (currentChunk == null || currentChunk.unloadQueued || !spongeChunk.areNeighborsLoaded()) {
return false;
}
final short shortPos = this.blockPosToShort(pos);
if (spongeChunk.getQueuedLightingUpdates(lightType).contains(shortPos)) {
return false;
}
final Chunk chunk = currentChunk;
spongeChunk.getQueuedLightingUpdates(lightType).add(shortPos);
spongeChunk.getPendingLightUpdates().incrementAndGet();
spongeChunk.setLightUpdateTime(chunk.getWorld().getTotalWorldTime());
List<Chunk> neighbors = spongeChunk.getNeighbors();
// add diagonal chunks
Chunk southEastChunk = ((IMixinChunk) spongeChunk.getNeighborChunk(0)).getNeighborChunk(2);
Chunk southWestChunk = ((IMixinChunk) spongeChunk.getNeighborChunk(0)).getNeighborChunk(3);
Chunk northEastChunk = ((IMixinChunk) spongeChunk.getNeighborChunk(1)).getNeighborChunk(2);
Chunk northWestChunk = ((IMixinChunk) spongeChunk.getNeighborChunk(1)).getNeighborChunk(3);
if (southEastChunk != null) {
neighbors.add(southEastChunk);
}
if (southWestChunk != null) {
neighbors.add(southWestChunk);
}
if (northEastChunk != null) {
neighbors.add(northEastChunk);
}
if (northWestChunk != null) {
neighbors.add(northWestChunk);
}
for (net.minecraft.world.chunk.Chunk neighborChunk : neighbors) {
final IMixinChunk neighbor = (IMixinChunk) neighborChunk;
neighbor.getPendingLightUpdates().incrementAndGet();
neighbor.setLightUpdateTime(chunk.getWorld().getTotalWorldTime());
}
// System.out.println("size = " + ((ThreadPoolExecutor) this.lightExecutorService).getQueue().size());
if (SpongeImpl.getServer().isCallingFromMinecraftThread()) {
this.lightExecutorService.execute(() -> {
this.checkLightAsync(lightType, pos, chunk, neighbors);
});
} else {
this.checkLightAsync(lightType, pos, chunk, neighbors);
}
return true;
}
use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.
the class TileEntityActivation method checkIfActive.
/**
* Checks if the tileentity is active for this tick.
*
* @param tileEntity The tileentity to check for activity
* @return Whether the given tileentity should be active
*/
public static boolean checkIfActive(TileEntity tileEntity) {
if (tileEntity.getWorld() == null || tileEntity.getWorld().isRemote || !(tileEntity instanceof ITickable)) {
return true;
}
final World world = tileEntity.getWorld();
final IMixinChunk activeChunk = ((IMixinTileEntity) tileEntity).getActiveChunk();
if (activeChunk == null) {
// Should never happen but just in case for mods, always tick
return true;
}
long currentTick = SpongeImpl.getServer().getTickCounter();
IModData_Activation spongeTileEntity = (IModData_Activation) tileEntity;
boolean isActive = activeChunk.isPersistedChunk() || spongeTileEntity.getActivatedTick() >= currentTick || spongeTileEntity.getDefaultActivationState();
// Should this entity tick?
if (!isActive) {
if (spongeTileEntity.getActivatedTick() == Integer.MIN_VALUE) {
// Has not come across a player
return false;
}
}
// check tick rate
if (isActive && world.getWorldInfo().getWorldTotalTime() % spongeTileEntity.getSpongeTickRate() != 0L) {
isActive = false;
}
return isActive;
}
Aggregations