Search in sources :

Example 1 with ShortRangeTelepadHandler

use of micdoodle8.mods.galacticraft.planets.asteroids.dimension.ShortRangeTelepadHandler in project Galacticraft by micdoodle8.

the class AsteroidsTickHandlerServer method onServerTick.

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    // Prevent issues when clients switch to LAN servers
    if (server == null) {
        return;
    }
    if (event.phase == TickEvent.Phase.START) {
        TileEntityMinerBase.checkNewMinerBases();
        if (AsteroidsTickHandlerServer.spaceRaceData == null) {
            World world = server.worldServerForDimension(0);
            AsteroidsTickHandlerServer.spaceRaceData = (ShortRangeTelepadHandler) world.getMapStorage().loadData(ShortRangeTelepadHandler.class, ShortRangeTelepadHandler.saveDataID);
            if (AsteroidsTickHandlerServer.spaceRaceData == null) {
                AsteroidsTickHandlerServer.spaceRaceData = new ShortRangeTelepadHandler(ShortRangeTelepadHandler.saveDataID);
                world.getMapStorage().setData(ShortRangeTelepadHandler.saveDataID, AsteroidsTickHandlerServer.spaceRaceData);
            }
        }
        int index = -1;
        for (EntityAstroMiner miner : activeMiners) {
            index++;
            if (miner.isDead) {
                // minerIt.remove();  Don't remove it, we want the index number to be static for the others
                continue;
            }
            if (miner.playerMP != null) {
                GCPlayerStats stats = GCPlayerStats.get(miner.playerMP);
                if (stats != null) {
                    List<BlockVec3> list = stats.getActiveAstroMinerChunks();
                    boolean inListAlready = false;
                    Iterator<BlockVec3> it = list.iterator();
                    while (it.hasNext()) {
                        BlockVec3 data = it.next();
                        if (// SideDoneBits won't be saved to NBT, but during an active server session we can use it as a cross-reference to the index here - it's a 4th data int hidden inside a BlockVec3
                        data.sideDoneBits == index) {
                            if (miner.isDead) {
                                // Player stats should not save position of dead AstroMiner entity (probably broken by player deliberately breaking it)
                                it.remove();
                            } else {
                                data.x = miner.chunkCoordX;
                                data.z = miner.chunkCoordZ;
                            }
                            inListAlready = true;
                            break;
                        }
                    }
                    if (!inListAlready && !miner.isDead) {
                        BlockVec3 data = new BlockVec3(miner.chunkCoordX, miner.dimension, miner.chunkCoordZ);
                        data.sideDoneBits = index;
                        list.add(data);
                    }
                }
            }
        }
    }
}
Also used : EntityAstroMiner(micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityAstroMiner) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) ShortRangeTelepadHandler(micdoodle8.mods.galacticraft.planets.asteroids.dimension.ShortRangeTelepadHandler) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)1 ShortRangeTelepadHandler (micdoodle8.mods.galacticraft.planets.asteroids.dimension.ShortRangeTelepadHandler)1 EntityAstroMiner (micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityAstroMiner)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1