Search in sources :

Example 21 with ChunkProviderServer

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

the class WorldServerShipManager method injectChunkIntoWorldServer.

private void injectChunkIntoWorldServer(@Nonnull Chunk chunk, int x, int z) {
    ChunkProviderServer provider = world.getChunkProvider();
    provider.loadedChunks.put(ChunkPos.asLong(x, z), chunk);
    chunk.onLoad();
    chunk.checkLight();
    chunk.markDirty();
}
Also used : ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer)

Example 22 with ChunkProviderServer

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

the class PhysicsObject method unload.

void unload() {
    watchingPlayers.clear();
    if (!getWorld().isRemote) {
        ChunkProviderServer provider = (ChunkProviderServer) getWorld().getChunkProvider();
        for (ChunkPos chunkPos : getChunkClaim()) {
            provider.queueUnload(claimedChunkCache.getChunkAt(chunkPos.x, chunkPos.z));
        }
    } else {
        ChunkProviderClient provider = (ChunkProviderClient) getWorld().getChunkProvider();
        for (ChunkPos chunkPos : getChunkClaim()) {
            provider.unloadChunk(chunkPos.x, chunkPos.z);
        }
        getShipRenderer().killRenderers();
    }
}
Also used : ChunkProviderClient(net.minecraft.client.multiplayer.ChunkProviderClient) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 23 with ChunkProviderServer

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

the class SurroundingChunkCacheController method updateChunkCache.

public void updateChunkCache() {
    AxisAlignedBB cacheBB = physicsObject.getShipBoundingBox();
    // Check if all those surrounding chunks are loaded
    BlockPos min = new BlockPos(cacheBB.minX, Math.max(cacheBB.minY, 0), cacheBB.minZ);
    BlockPos max = new BlockPos(cacheBB.maxX, Math.min(cacheBB.maxY, 255), cacheBB.maxZ);
    if (!physicsObject.getWorld().isRemote) {
        ChunkProviderServer serverChunkProvider = (ChunkProviderServer) physicsObject.getWorld().getChunkProvider();
        int chunkMinX = min.getX() >> 4;
        int chunkMaxX = max.getX() >> 4;
        int chunkMinZ = min.getZ() >> 4;
        int chunkMaxZ = max.getZ() >> 4;
        boolean areSurroundingChunksLoaded = true;
        outer: for (int chunkX = chunkMinX; chunkX <= chunkMaxX; chunkX++) {
            for (int chunkZ = chunkMinZ; chunkZ <= chunkMaxZ; chunkZ++) {
                areSurroundingChunksLoaded = serverChunkProvider.chunkExists(chunkX, chunkZ);
                if (!areSurroundingChunksLoaded) {
                    break outer;
                }
            }
        }
        if (areSurroundingChunksLoaded) {
            cachedChunks = new ChunkCache(physicsObject.getWorld(), min, max, 0);
        }
    } else {
        cachedChunks = new ChunkCache(physicsObject.getWorld(), min, max, 0);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ChunkCache(net.minecraft.world.ChunkCache) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) BlockPos(net.minecraft.util.math.BlockPos)

Example 24 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project Galacticraft by micdoodle8.

the class TickHandlerServer method onServerTick.

@SubscribeEvent
public void onServerTick(ServerTickEvent event) {
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    // Prevent issues when clients switch to LAN servers
    if (server == null) {
        return;
    }
    if (event.phase == Phase.START) {
        if (timerHoustonCommand > 0) {
            if (--timerHoustonCommand == 0) {
                CommandGCHouston.reset();
            }
        }
        for (ScheduledDimensionChange change : TickHandlerServer.scheduledDimensionChanges) {
            try {
                GCPlayerStats stats = GCPlayerStats.get(change.getPlayer());
                final WorldProvider provider = WorldUtil.getProviderForDimensionServer(change.getDimensionId());
                if (provider != null) {
                    final int dim = GCCoreUtil.getDimensionID(provider);
                    GCLog.info("Found matching world (" + dim + ") for name: " + change.getDimensionId());
                    if (change.getPlayer().world instanceof WorldServer) {
                        final WorldServer world = (WorldServer) change.getPlayer().world;
                        WorldUtil.transferEntityToDimension(change.getPlayer(), dim, world);
                    }
                } else {
                    GCLog.severe("World not found when attempting to transfer entity to dimension: " + change.getDimensionId());
                }
                stats.setTeleportCooldown(10);
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_CLOSE_GUI, GCCoreUtil.getDimensionID(change.getPlayer().world), new Object[] {}), change.getPlayer());
            } catch (Exception e) {
                GCLog.severe("Error occurred when attempting to transfer entity to dimension: " + change.getDimensionId());
                e.printStackTrace();
            }
        }
        TickHandlerServer.scheduledDimensionChanges.clear();
        if (MapUtil.calculatingMap.get()) {
            MapUtil.BiomeMapNextTick_MultiThreaded();
        } else if (!MapUtil.doneOverworldTexture) {
            MapUtil.makeOverworldTexture();
        }
        if (TickHandlerServer.spaceRaceData == null) {
            World world = server.getWorld(0);
            TickHandlerServer.spaceRaceData = (WorldDataSpaceRaces) world.getMapStorage().getOrLoadData(WorldDataSpaceRaces.class, WorldDataSpaceRaces.saveDataID);
            if (TickHandlerServer.spaceRaceData == null) {
                TickHandlerServer.spaceRaceData = new WorldDataSpaceRaces(WorldDataSpaceRaces.saveDataID);
                world.getMapStorage().setData(WorldDataSpaceRaces.saveDataID, TickHandlerServer.spaceRaceData);
            }
        }
        SpaceRaceManager.tick();
        TileEntityOxygenSealer.onServerTick();
        if (TickHandlerServer.tickCount % 33 == 0) {
            WorldServer[] worlds = server.worlds;
            for (int i = worlds.length - 1; i >= 0; i--) {
                WorldServer world = worlds[i];
                TileEntityPainter.onServerTick(world);
            }
        }
        if (TickHandlerServer.tickCount % 100 == 0) {
            WorldServer[] worlds = server.worlds;
            for (int i = 0; i < worlds.length; i++) {
                WorldServer world = worlds[i];
                ChunkProviderServer chunkProviderServer = world.getChunkProvider();
                Map<Long, List<Footprint>> footprintMap = TickHandlerServer.serverFootprintMap.get(GCCoreUtil.getDimensionID(world));
                if (footprintMap != null) {
                    boolean mapChanged = false;
                    if (chunkProviderServer != null) {
                        Iterator iterator = chunkProviderServer.getLoadedChunks().iterator();
                        while (iterator.hasNext()) {
                            Chunk chunk = (Chunk) iterator.next();
                            long chunkKey = ChunkPos.asLong(chunk.x, chunk.z);
                            List<Footprint> footprints = footprintMap.get(chunkKey);
                            if (footprints != null) {
                                List<Footprint> toRemove = new ArrayList<Footprint>();
                                for (int j = 0; j < footprints.size(); j++) {
                                    footprints.get(j).age += 100;
                                    if (footprints.get(j).age >= Footprint.MAX_AGE) {
                                        toRemove.add(footprints.get(j));
                                    }
                                }
                                if (!toRemove.isEmpty()) {
                                    footprints.removeAll(toRemove);
                                }
                                footprintMap.put(chunkKey, footprints);
                                mapChanged = true;
                                GalacticraftCore.packetPipeline.sendToDimension(new PacketSimple(EnumSimplePacket.C_UPDATE_FOOTPRINT_LIST, worlds[i].provider.getDimension(), new Object[] { chunkKey, footprints.toArray(new Footprint[footprints.size()]) }), worlds[i].provider.getDimension());
                            }
                        }
                    }
                    if (mapChanged) {
                        TickHandlerServer.serverFootprintMap.put(GCCoreUtil.getDimensionID(world), footprintMap);
                    }
                }
            }
        }
        if (!footprintBlockChanges.isEmpty()) {
            for (BlockVec3Dim targetPoint : footprintBlockChanges) {
                WorldServer[] worlds = server.worlds;
                for (int i = 0; i < worlds.length; i++) {
                    WorldServer world = worlds[i];
                    if (GCCoreUtil.getDimensionID(world) == targetPoint.dim) {
                        long chunkKey = ChunkPos.asLong((int) targetPoint.x >> 4, (int) targetPoint.z >> 4);
                        GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_FOOTPRINTS_REMOVED, GCCoreUtil.getDimensionID(world), new Object[] { chunkKey, new BlockVec3(targetPoint.x, targetPoint.y, targetPoint.z) }), new NetworkRegistry.TargetPoint(targetPoint.dim, targetPoint.x, targetPoint.y, targetPoint.z, 50));
                    // Map<Long, List<Footprint>> footprintMap = TickHandlerServer.serverFootprintMap.get(world.provider.dimensionId);
                    // 
                    // if (footprintMap != null && !footprintMap.isEmpty())
                    // {
                    // List<Footprint> footprints = footprintMap.get(chunkKey);
                    // if (footprints != null)
                    // GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_UPDATE_FOOTPRINT_LIST, new Object[] { chunkKey, footprints.toArray(new Footprint[footprints.size()]) }), new NetworkRegistry.TargetPoint(targetPoint.dim, targetPoint.x, targetPoint.y, targetPoint.z, 50));
                    // }
                    }
                }
            }
            footprintBlockChanges.clear();
        }
        if (tickCount % 20 == 0) {
            if (!playersRequestingMapData.isEmpty()) {
                File baseFolder = new File(DimensionManager.getCurrentSaveRootDirectory(), "galacticraft/overworldMap");
                if (!baseFolder.exists() && !baseFolder.mkdirs()) {
                    GCLog.severe("Base folder(s) could not be created: " + baseFolder.getAbsolutePath());
                } else {
                    ArrayList<EntityPlayerMP> copy = new ArrayList<EntityPlayerMP>(playersRequestingMapData);
                    BufferedImage reusable = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
                    for (EntityPlayerMP playerMP : copy) {
                        GCPlayerStats stats = GCPlayerStats.get(playerMP);
                        MapUtil.makeVanillaMap(playerMP.dimension, (int) Math.floor(stats.getCoordsTeleportedFromZ()) >> 4, (int) Math.floor(stats.getCoordsTeleportedFromZ()) >> 4, baseFolder, reusable);
                    }
                    playersRequestingMapData.removeAll(copy);
                }
            }
        }
        TickHandlerServer.tickCount++;
        EnergyNetwork.tickCount++;
    } else if (event.phase == Phase.END) {
        for (FluidNetwork network : new ArrayList<>(fluidNetworks)) {
            if (!network.pipes.isEmpty()) {
                network.tickEnd();
            } else {
                fluidNetworks.remove(network);
            }
        }
        int maxPasses = 10;
        while (!TickHandlerServer.networkTicks.isEmpty()) {
            LinkedList<EnergyNetwork> pass = new LinkedList<>();
            pass.addAll(TickHandlerServer.networkTicks);
            TickHandlerServer.networkTicks.clear();
            for (EnergyNetwork grid : pass) {
                grid.tickEnd();
            }
            if (--maxPasses <= 0) {
                break;
            }
        }
        maxPasses = 10;
        while (!TickHandlerServer.oxygenTransmitterUpdates.isEmpty()) {
            LinkedList<TileEntityFluidTransmitter> pass = new LinkedList<>();
            pass.addAll(TickHandlerServer.oxygenTransmitterUpdates);
            TickHandlerServer.oxygenTransmitterUpdates.clear();
            for (TileEntityFluidTransmitter newTile : pass) {
                if (!newTile.isInvalid()) {
                    newTile.refresh();
                }
            }
            if (--maxPasses <= 0) {
                break;
            }
        }
        maxPasses = 10;
        while (!TickHandlerServer.energyTransmitterUpdates.isEmpty()) {
            LinkedList<TileBaseConductor> pass = new LinkedList<>();
            pass.addAll(TickHandlerServer.energyTransmitterUpdates);
            TickHandlerServer.energyTransmitterUpdates.clear();
            for (TileBaseConductor newTile : pass) {
                // See https://github.com/micdoodle8/Galacticraft/issues/3700
                if (newTile != null && !newTile.isInvalid()) {
                    newTile.refresh();
                }
            }
            if (--maxPasses <= 0) {
                break;
            }
        }
    }
}
Also used : EnergyNetwork(micdoodle8.mods.galacticraft.core.energy.grid.EnergyNetwork) TileBaseConductor(micdoodle8.mods.galacticraft.core.energy.tile.TileBaseConductor) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) BlockVec3Dim(micdoodle8.mods.galacticraft.api.vector.BlockVec3Dim) BufferedImage(java.awt.image.BufferedImage) ScheduledDimensionChange(micdoodle8.mods.galacticraft.core.wrappers.ScheduledDimensionChange) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) WorldProvider(net.minecraft.world.WorldProvider) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) WorldDataSpaceRaces(micdoodle8.mods.galacticraft.core.dimension.WorldDataSpaceRaces) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) Chunk(net.minecraft.world.chunk.Chunk) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) MinecraftServer(net.minecraft.server.MinecraftServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) File(java.io.File) TileEntityFluidTransmitter(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTransmitter) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 25 with ChunkProviderServer

use of net.minecraft.world.gen.ChunkProviderServer in project Galacticraft by micdoodle8.

the class BlockVec3 method getTileEntityForce.

public TileEntity getTileEntityForce(World world) {
    int chunkx = this.x >> 4;
    int chunkz = this.z >> 4;
    if (world.getChunkProvider().getLoadedChunk(chunkx, chunkz) != null)
        return world.getTileEntity(this.toBlockPos());
    Chunk chunk = ((ChunkProviderServer) world.getChunkProvider()).loadChunk(chunkx, chunkz);
    return chunk.getTileEntity(new BlockPos(this.x & 15, this.y, this.z & 15), Chunk.EnumCreateEntityType.IMMEDIATE);
}
Also used : ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk)

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