Search in sources :

Example 1 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class MixinMinecraftServer method prepareSpawnArea.

@Override
public void prepareSpawnArea(WorldServer worldServer) {
    if (!((WorldProperties) worldServer.getWorldInfo()).doesGenerateSpawnOnLoad()) {
        return;
    }
    IMixinChunkProviderServer chunkProviderServer = (IMixinChunkProviderServer) worldServer.getChunkProvider();
    chunkProviderServer.setForceChunkRequests(true);
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    try (GenerationContext context = GenerationPhase.State.TERRAIN_GENERATION.createPhaseContext().source(worldServer).world(worldServer).buildAndSwitch()) {
        int i = 0;
        this.setUserMessage("menu.generatingTerrain");
        LOGGER.info("Preparing start region for level {} ({})", ((IMixinWorldServer) worldServer).getDimensionId(), ((World) worldServer).getName());
        BlockPos blockpos = worldServer.getSpawnPoint();
        long j = MinecraftServer.getCurrentTimeMillis();
        for (int k = -192; k <= 192 && this.isServerRunning(); k += 16) {
            for (int l = -192; l <= 192 && this.isServerRunning(); l += 16) {
                long i1 = MinecraftServer.getCurrentTimeMillis();
                if (i1 - j > 1000L) {
                    this.outputPercentRemaining("Preparing spawn area", i * 100 / 625);
                    j = i1;
                }
                ++i;
                worldServer.getChunkProvider().provideChunk(blockpos.getX() + k >> 4, blockpos.getZ() + l >> 4);
            }
        }
        this.clearCurrentTask();
    }
    chunkProviderServer.setForceChunkRequests(false);
}
Also used : GenerationContext(org.spongepowered.common.event.tracking.phase.generation.GenerationContext) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) BlockPos(net.minecraft.util.math.BlockPos) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Example 2 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class DamageEventHandler method findFirstMatchingBlock.

public static Location<World> findFirstMatchingBlock(Entity entity, AxisAlignedBB bb, Predicate<IBlockState> predicate) {
    int i = MathHelper.floor(bb.minX);
    int j = MathHelper.floor(bb.maxX + 1.0D);
    int k = MathHelper.floor(bb.minY);
    int l = MathHelper.floor(bb.maxY + 1.0D);
    int i1 = MathHelper.floor(bb.minZ);
    int j1 = MathHelper.floor(bb.maxZ + 1.0D);
    final IMixinChunkProviderServer spongeChunkProvider = (IMixinChunkProviderServer) entity.world.getChunkProvider();
    for (int k1 = i; k1 < j; ++k1) {
        for (int l1 = k; l1 < l; ++l1) {
            for (int i2 = i1; i2 < j1; ++i2) {
                BlockPos blockPos = new BlockPos(k1, l1, i2);
                final Chunk chunk = spongeChunkProvider.getLoadedChunkWithoutMarkingActive(blockPos.getX() >> 4, blockPos.getZ() >> 4);
                if (chunk == null) {
                    continue;
                }
                if (predicate.test(chunk.getBlockState(blockPos))) {
                    return new Location<>((World) entity.world, k1, l1, i2);
                }
            }
        }
    }
    // Entity is source of fire
    return ((org.spongepowered.api.entity.Entity) entity).getLocation();
}
Also used : IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Entity(net.minecraft.entity.Entity) 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) Location(org.spongepowered.api.world.Location) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation)

Example 3 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class MixinMapGenStructure method generateStructure.

/**
 * @author blood - October 22nd, 2016
 * @reason Prevents CME's by avoiding recursive calls while generating structures
 *
 * @param worldIn The world
 * @param randomIn The rand
 * @Param chunkCoord The chunk position
 * @return true if generation was successful
 */
@Overwrite
public synchronized boolean generateStructure(World worldIn, Random randomIn, ChunkPos chunkCoord) {
    if (generatingStructures) {
        return false;
    }
    Chunk chunk = ((IMixinChunkProviderServer) worldIn.getChunkProvider()).getLoadedChunkWithoutMarkingActive(chunkCoord.x, chunkCoord.z);
    if (chunk == null) {
        return false;
    }
    this.initializeStructureData(worldIn);
    int i = (chunkCoord.x << 4) + 8;
    int j = (chunkCoord.z << 4) + 8;
    boolean flag = false;
    generatingStructures = true;
    for (StructureStart structurestart : this.structureMap.values()) {
        if (structurestart.isSizeableStructure() && structurestart.isValidForPostProcess(chunkCoord) && structurestart.getBoundingBox().intersectsWith(i, j, i + 15, j + 15)) {
            structurestart.generateStructure(worldIn, randomIn, new StructureBoundingBox(i, j, i + 15, j + 15));
            structurestart.notifyPostProcessAt(chunkCoord);
            flag = true;
            this.setStructureStart(structurestart.getChunkPosX(), structurestart.getChunkPosZ(), structurestart);
        }
    }
    generatingStructures = false;
    return flag;
}
Also used : StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) StructureStart(net.minecraft.world.gen.structure.StructureStart) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class EntityActivationRange method activateEntities.

/**
 * Find what entities are in range of the players in the world and set
 * active if in range.
 *
 * @param world The world to perform activation checks in
 */
public static void activateEntities(World world) {
    if (((IMixinWorld) world).isFake()) {
        return;
    }
    for (EntityPlayer player : world.playerEntities) {
        int maxRange = 0;
        for (Integer range : maxActivationRanges.values()) {
            if (range > maxRange) {
                maxRange = range;
            }
        }
        maxRange = Math.min((((org.spongepowered.api.world.World) world).getViewDistance() << 4) - 8, maxRange);
        ((IModData_Activation) player).setActivatedTick(SpongeImpl.getServer().getTickCounter());
        growBb(maxBB, player.getEntityBoundingBox(), maxRange, 256, maxRange);
        int i = MathHelper.floor(maxBB.minX / 16.0D);
        int j = MathHelper.floor(maxBB.maxX / 16.0D);
        int k = MathHelper.floor(maxBB.minZ / 16.0D);
        int l = MathHelper.floor(maxBB.maxZ / 16.0D);
        for (int i1 = i; i1 <= j; ++i1) {
            for (int j1 = k; j1 <= l; ++j1) {
                WorldServer worldserver = (WorldServer) world;
                Chunk chunk = ((IMixinChunkProviderServer) worldserver.getChunkProvider()).getLoadedChunkWithoutMarkingActive(i1, j1);
                if (chunk != null) {
                    activateChunkEntities(player, chunk);
                }
            }
        }
    }
}
Also used : IModData_Activation(org.spongepowered.common.mixin.plugin.entityactivation.interfaces.IModData_Activation) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Example 5 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class MixinWorld_Tracker method setNotifier.

@Override
public void setNotifier(int x, int y, int z, @Nullable UUID uuid) {
    final Chunk chunk = ((IMixinChunkProviderServer) this.chunkProvider).getLoadedChunkWithoutMarkingActive(x >> 4, z >> 4);
    if (chunk == null) {
        return;
    }
    BlockPos pos = new BlockPos(x, y, z);
    ((IMixinChunk) chunk).setBlockNotifier(pos, uuid);
}
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)

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