Search in sources :

Example 6 with IMixinChunkProviderServer

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);
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) BlockPos(net.minecraft.util.math.BlockPos) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 7 with IMixinChunkProviderServer

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);
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Example 8 with IMixinChunkProviderServer

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);
        }
    }
}
Also used : NotifyNeighborBlockEvent(org.spongepowered.api.event.block.NotifyNeighborBlockEvent) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) EnumFacing(net.minecraft.util.EnumFacing) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Direction(org.spongepowered.api.util.Direction)

Example 9 with IMixinChunkProviderServer

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;
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 10 with IMixinChunkProviderServer

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;
}
Also used : IMixinMinecraftServer(org.spongepowered.common.interfaces.IMixinMinecraftServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) ServerWorldEventHandler(net.minecraft.world.ServerWorldEventHandler) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) World(net.minecraft.world.World) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) IMixinMinecraftServer(org.spongepowered.common.interfaces.IMixinMinecraftServer) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)24 Chunk (net.minecraft.world.chunk.Chunk)16 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)15 BlockPos (net.minecraft.util.math.BlockPos)9 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)5 Direction (org.spongepowered.api.util.Direction)4 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)4 Vector3i (com.flowpowered.math.vector.Vector3i)3 WorldServer (net.minecraft.world.WorldServer)3 World (org.spongepowered.api.world.World)3 Overwrite (org.spongepowered.asm.mixin.Overwrite)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 IMixinWorld (org.spongepowered.common.interfaces.world.IMixinWorld)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EnumFacing (net.minecraft.util.EnumFacing)2 World (net.minecraft.world.World)2 NotifyNeighborBlockEvent (org.spongepowered.api.event.block.NotifyNeighborBlockEvent)2 Chunk (org.spongepowered.api.world.Chunk)2 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 WorldTimingsHandler (co.aikar.timings.WorldTimingsHandler)1