Search in sources :

Example 16 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project GIRSignals by German-Immersive-Railroading-Community.

the class IChunkloadable method loadChunkAndGetTile.

default boolean loadChunkAndGetTile(World world, BlockPos pos, BiConsumer<T, Chunk> consumer) {
    if (pos == null)
        return false;
    try {
        @SuppressWarnings("unchecked") final Callable<Boolean> call = () -> {
            TileEntity entity = null;
            Chunk chunk = world.getChunkFromBlockCoords(pos);
            final boolean flag = !chunk.isLoaded();
            if (flag) {
                if (world.isRemote) {
                    ChunkProviderClient client = (ChunkProviderClient) world.getChunkProvider();
                    chunk = client.loadChunk(chunk.x, chunk.z);
                } else {
                    ChunkProviderServer server = (ChunkProviderServer) world.getChunkProvider();
                    chunk = server.loadChunk(chunk.x, chunk.z);
                }
            }
            if (chunk == null)
                return false;
            entity = chunk.getTileEntity(pos, EnumCreateEntityType.IMMEDIATE);
            final boolean flag2 = entity != null;
            if (flag2) {
                consumer.accept((T) entity, chunk);
            }
            if (flag) {
                if (world.isRemote) {
                    ChunkProviderClient client = (ChunkProviderClient) world.getChunkProvider();
                    client.unloadChunk(chunk.x, chunk.z);
                } else {
                    ChunkProviderServer server = (ChunkProviderServer) world.getChunkProvider();
                    server.queueUnload(chunk);
                }
            }
            return flag2;
        };
        final MinecraftServer mcserver = world.getMinecraftServer();
        if (mcserver == null)
            return Minecraft.getMinecraft().addScheduledTask(call).get();
        return mcserver.callFromMainThread(call).get();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ChunkProviderClient(net.minecraft.client.multiplayer.ChunkProviderClient) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Chunk(net.minecraft.world.chunk.Chunk) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 17 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project GIRSignals by German-Immersive-Railroading-Community.

the class IChunkloadable method loadChunkAndGetBlock.

default boolean loadChunkAndGetBlock(World world, BlockPos pos, BiConsumer<IBlockState, Chunk> consumer) {
    if (pos == null)
        return false;
    try {
        final Callable<Boolean> call = () -> {
            IBlockState entity = null;
            Chunk chunk = world.getChunkFromBlockCoords(pos);
            final boolean flag = !chunk.isLoaded();
            if (flag) {
                if (world.isRemote) {
                    ChunkProviderClient client = (ChunkProviderClient) world.getChunkProvider();
                    chunk = client.loadChunk(chunk.x, chunk.z);
                } else {
                    ChunkProviderServer server = (ChunkProviderServer) world.getChunkProvider();
                    chunk = server.loadChunk(chunk.x, chunk.z);
                }
            }
            if (chunk == null)
                return false;
            entity = chunk.getBlockState(pos);
            final boolean flag2 = entity != null;
            if (flag2) {
                consumer.accept(entity, chunk);
            }
            if (flag) {
                if (world.isRemote) {
                    ChunkProviderClient client = (ChunkProviderClient) world.getChunkProvider();
                    client.unloadChunk(chunk.x, chunk.z);
                } else {
                    ChunkProviderServer server = (ChunkProviderServer) world.getChunkProvider();
                    server.queueUnload(chunk);
                }
            }
            return flag2;
        };
        final MinecraftServer mcserver = world.getMinecraftServer();
        if (mcserver == null)
            return Minecraft.getMinecraft().addScheduledTask(call).get();
        return mcserver.callFromMainThread(call).get();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : ChunkProviderClient(net.minecraft.client.multiplayer.ChunkProviderClient) IBlockState(net.minecraft.block.state.IBlockState) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Chunk(net.minecraft.world.chunk.Chunk) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 18 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project Crossroads by Crossroads-Development.

the class MultiPistonBase method getEntitiesMultiChunk.

/**
 * An alternate version of World#getEntitiesWithinAABBExcludingEntity that checks a 3x3x3 cube of mini chunks (16x16x16 cubes within chunks) for entities.
 * This is less efficient than the standard method, but necessary to fix a bug.
 */
private static ArrayList<Entity> getEntitiesMultiChunk(AxisAlignedBB checkBox, World worldIn) {
    ArrayList<Entity> found = new ArrayList<Entity>();
    int i = MathHelper.floor((checkBox.minX - World.MAX_ENTITY_RADIUS) / 16.0D) - 1;
    int j = MathHelper.floor((checkBox.maxX + World.MAX_ENTITY_RADIUS) / 16.0D) + 1;
    int k = MathHelper.floor((checkBox.minZ - World.MAX_ENTITY_RADIUS) / 16.0D) - 1;
    int l = MathHelper.floor((checkBox.maxZ + World.MAX_ENTITY_RADIUS) / 16.0D) + 1;
    int yMin = MathHelper.clamp(MathHelper.floor((checkBox.minY - World.MAX_ENTITY_RADIUS) / 16.0D) - 1, 0, 15);
    int yMax = MathHelper.clamp(MathHelper.floor((checkBox.maxY + World.MAX_ENTITY_RADIUS) / 16.0D) + 1, 0, 15);
    for (int iLoop = i; iLoop <= j; ++iLoop) {
        for (int kLoop = k; kLoop <= l; ++kLoop) {
            if (((ChunkProviderServer) worldIn.getChunkProvider()).chunkExists(iLoop, kLoop)) {
                Chunk chunk = worldIn.getChunkFromChunkCoords(iLoop, kLoop);
                for (int yLoop = yMin; yLoop <= yMax; ++yLoop) {
                    if (!chunk.getEntityLists()[yLoop].isEmpty()) {
                        for (Entity entity : chunk.getEntityLists()[yLoop]) {
                            if (entity.getEntityBoundingBox().intersectsWith(checkBox)) {
                                found.add(entity);
                            }
                        }
                    }
                }
            }
        }
    }
    return found;
}
Also used : Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Chunk(net.minecraft.world.chunk.Chunk)

Example 19 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project Engine by VoltzEngine-Project.

the class MassRegistry method getMass.

@Override
public double getMass(World world, int x, int y, int z) {
    double mass;
    if (world != null) {
        //Checks if the chunk is loaded
        if (world instanceof WorldServer) {
            ChunkProviderServer providerServer = ((WorldServer) world).theChunkProviderServer;
            if (!providerServer.chunkExists(x >> 4, z >> 4)) {
                return -1;
            }
        }
        Block block = world.getBlock(x, y, z);
        int meta = world.getBlockMetadata(x, y, z);
        TileEntity tile = world.getTileEntity(x, y, z);
        if (tile instanceof IHasMass) {
            mass = ((IHasMass) tile).getMass();
            if (mass >= 0) {
                return mass;
            }
        }
        mass = getMass(block, meta);
        return mass >= 0 ? mass : getMass(block);
    }
    return -1;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IHasMass(com.builtbroken.mc.api.IHasMass) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Block(net.minecraft.block.Block) WorldServer(net.minecraft.world.WorldServer)

Example 20 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldServerShipManager method loadAndUnloadShips.

private void loadAndUnloadShips() {
    QueryableShipData queryableShipData = QueryableShipData.get(world);
    // Load the ships that are required immediately.
    for (final UUID toLoadID : loadQueue) {
        Optional<ShipData> toLoadOptional = queryableShipData.getShip(toLoadID);
        if (!toLoadOptional.isPresent()) {
            throw new IllegalStateException("No ship found for ID:\n" + toLoadID);
        }
        ShipData toLoad = toLoadOptional.get();
        if (loadedShips.containsKey(toLoadID)) {
            throw new IllegalStateException("Tried loading a ShipData that was already loaded?\n" + toLoad);
        }
        // Remove this ship from the background loading set, if it is in it.
        loadingInBackground.remove(toLoadID);
        // Finally, load the ship.
        if (VSConfig.showAnnoyingDebugOutput) {
            System.out.println("Attempting to load ship " + toLoad);
        }
        PhysicsObject physicsObject = new PhysicsObject(world, toLoad);
        PhysicsObject old = loadedShips.put(toLoad.getUuid(), physicsObject);
        if (old != null) {
            throw new IllegalStateException("How did we already have a ship loaded for " + toLoad);
        }
    }
    loadQueue.clear();
    // Load ships that aren't required immediately in the background.
    for (final UUID toLoadID : backgroundLoadQueue) {
        // Skip if this ship is already being loaded in the background,.
        if (loadingInBackground.contains(toLoadID)) {
            // Already loading this ship in the background
            continue;
        }
        // Make sure there isn't an already loaded ship with this UUID.
        if (loadedShips.containsKey(toLoadID)) {
            // continue; // temp, need to fix WorldShipLoadingController.determineLoadAndUnload()
            throw new IllegalStateException("Tried loading a ShipData that was already loaded? Ship ID is\n" + toLoadID);
        }
        // Then try getting the ShipData for this UUID.
        Optional<ShipData> toLoadOptional = queryableShipData.getShip(toLoadID);
        if (!toLoadOptional.isPresent()) {
            throw new IllegalStateException("No ship found for ID:\n" + toLoadID);
        }
        ShipData toLoad = toLoadOptional.get();
        loadingInBackground.add(toLoadID);
        if (VSConfig.showAnnoyingDebugOutput) {
            System.out.println("Attempting to load " + toLoad + " in the background.");
        }
        ChunkProviderServer chunkProviderServer = world.getChunkProvider();
        for (ChunkPos chunkPos : toLoad.getChunkClaim()) {
            @Nonnull Runnable returnTask = () -> {
                if (VSConfig.showAnnoyingDebugOutput) {
                    System.out.println("Loaded ship chunk " + chunkPos);
                }
            };
            chunkProviderServer.loadChunk(chunkPos.x, chunkPos.z, returnTask);
        }
    }
    backgroundLoadQueue.clear();
    // Unload far away ships immediately.
    for (final UUID toUnloadID : unloadQueue) {
        // Make sure we have a ship with this ID that can be unloaded
        if (!loadedShips.containsKey(toUnloadID)) {
            throw new IllegalStateException("Tried unloading a ShipData that isn't loaded? Ship ID is\n" + toUnloadID);
        }
        PhysicsObject physicsObject = getPhysObjectFromUUID(toUnloadID);
        if (VSConfig.showAnnoyingDebugOutput) {
            System.out.println("Attempting to unload " + physicsObject);
        }
        physicsObject.unload();
        boolean success = loadedShips.remove(toUnloadID, physicsObject);
        if (!success) {
            throw new IllegalStateException("How did we fail to unload " + physicsObject.getShipData());
        }
    }
    unloadQueue.clear();
}
Also used : Nonnull(javax.annotation.Nonnull) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) ChunkPos(net.minecraft.util.math.ChunkPos) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData)

Aggregations

ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)32 Chunk (net.minecraft.world.chunk.Chunk)14 WorldServer (net.minecraft.world.WorldServer)13 IChunkProvider (net.minecraft.world.chunk.IChunkProvider)6 TileEntity (net.minecraft.tileentity.TileEntity)4 ArrayList (java.util.ArrayList)3 Block (net.minecraft.block.Block)3 ChunkProviderClient (net.minecraft.client.multiplayer.ChunkProviderClient)3 Entity (net.minecraft.entity.Entity)3 MinecraftServer (net.minecraft.server.MinecraftServer)3 BlockPos (net.minecraft.util.math.BlockPos)3 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)3 World (net.minecraft.world.World)3 IHasMass (com.builtbroken.mc.api.IHasMass)2 Collection (java.util.Collection)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)2 EntitySelector (com.builtbroken.mc.prefab.entity.selector.EntitySelector)1 Predicate (com.google.common.base.Predicate)1