Search in sources :

Example 1 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project MorePlanets by SteveKunG.

the class ChunkGeneratorNibiru method generateOil.

private void generateOil(World world, Random rand, int xx, int zz) {
    BlockVec3 pos = new BlockVec3();
    if (this.oilPresent(world, rand, xx, zz, pos)) {
        int x = pos.x;
        int cy = pos.y;
        int z = pos.z;
        int r = 3 + rand.nextInt(5);
        int r2 = r * r;
        for (int bx = -r; bx <= r; bx++) {
            for (int by = -r + 2; by <= r - 2; by++) {
                for (int bz = -r; bz <= r; bz++) {
                    int d2 = bx * bx + by * by * 3 + bz * bz;
                    if (d2 <= r2) {
                        if (this.checkBlockOil(world, bx + x - 1, by + cy, bz + z)) {
                            continue;
                        }
                        if (this.checkBlockOil(world, bx + x + 1, by + cy, bz + z)) {
                            continue;
                        }
                        if (this.checkBlockOil(world, bx + x, by + cy - 1, bz + z)) {
                            continue;
                        }
                        if (this.checkBlockOil(world, bx + x, by + cy, bz + z - 1)) {
                            continue;
                        }
                        if (this.checkBlockOil(world, bx + x, by + cy, bz + z + 1)) {
                            continue;
                        }
                        world.setBlockState(new BlockPos(bx + x, by + cy, bz + z), GCBlocks.crudeOil.getDefaultState(), 2);
                    }
                }
            }
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 2 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project MorePlanets by SteveKunG.

the class ChunkGeneratorNibiru method generateGas.

private void generateGas(World world, Random rand, int xx, int zz) {
    BlockVec3 pos = new BlockVec3();
    if (this.gasPresent(world, rand, xx, zz, pos)) {
        int x = pos.x;
        int cy = pos.y;
        int z = pos.z;
        int r = 2 + rand.nextInt(2);
        int r2 = r * r;
        for (int bx = -r; bx <= r; bx++) {
            for (int by = -r + 2; by <= r - 2; by++) {
                for (int bz = -r; bz <= r; bz++) {
                    int d2 = bx * bx + by * by * 3 + bz * bz;
                    if (d2 <= r2) {
                        if (this.checkBlockGas(world, bx + x - 1, by + cy, bz + z)) {
                            continue;
                        }
                        if (this.checkBlockGas(world, bx + x + 1, by + cy, bz + z)) {
                            continue;
                        }
                        if (this.checkBlockGas(world, bx + x, by + cy - 1, bz + z)) {
                            continue;
                        }
                        if (this.checkBlockGas(world, bx + x, by + cy, bz + z - 1)) {
                            continue;
                        }
                        if (this.checkBlockGas(world, bx + x, by + cy, bz + z + 1)) {
                            continue;
                        }
                        world.setBlockState(new BlockPos(bx + x, by + cy, bz + z), NibiruBlocks.HELIUM_GAS_BLOCK.getDefaultState(), 2);
                    }
                }
            }
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 3 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 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)

Example 4 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class AsteroidsTickHandlerServer method loadAstroChunkList.

/**
 * How this works: every spawned or saved (in player stats) miner is added to the
 * activeMiners list here.
 * Once per server tick its position will be saved to player stats.
 * When the player quits, the saved miner positions will be saved with the player's stats NBT
 * When the player next loads, loadAstroChunkList will force load those chunks, therefore
 * reactivating AstroMiners if those chunks weren't already loaded.
 */
public static void loadAstroChunkList(List<BlockVec3> activeChunks) {
    List<BlockVec3> copyList = new LinkedList<>(activeChunks);
    activeChunks.clear();
    if (!(AsteroidsTickHandlerServer.loadingSavedChunks.getAndSet(true))) {
        for (BlockVec3 data : copyList) {
            WorldProvider p = WorldUtil.getProviderForDimensionServer(data.y);
            if (p != null && p.worldObj != null) {
                GCLog.debug("Loading chunk " + data.y + ": " + data.x + "," + data.z + " - should contain a miner!");
                ((WorldServer) p.worldObj).theChunkProviderServer.loadChunk(data.x, data.z);
            }
        }
        AsteroidsTickHandlerServer.loadingSavedChunks.set(false);
    }
}
Also used : WorldProvider(net.minecraft.world.WorldProvider) LinkedList(java.util.LinkedList) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 5 with BlockVec3

use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.

the class TileEntityBeamOutput method initiateReflector.

public void initiateReflector() {
    this.nodeList.clear();
    int chunkXMin = this.getPos().getX() - 15 >> 4;
    int chunkZMin = this.getPos().getZ() - 15 >> 4;
    int chunkXMax = this.getPos().getX() + 15 >> 4;
    int chunkZMax = this.getPos().getZ() + 15 >> 4;
    for (int cX = chunkXMin; cX <= chunkXMax; cX++) {
        for (int cZ = chunkZMin; cZ <= chunkZMax; cZ++) {
            if (this.worldObj.getChunkProvider().chunkExists(cX, cZ)) {
                Chunk chunk = this.worldObj.getChunkFromChunkCoords(cX, cZ);
                for (Object obj : chunk.getTileEntityMap().values()) {
                    if (obj != this && obj instanceof ILaserNode) {
                        BlockVec3 deltaPos = new BlockVec3(this).subtract(new BlockVec3(((ILaserNode) obj).getTile()));
                        if (deltaPos.x < 16 && deltaPos.y < 16 && deltaPos.z < 16) {
                            ILaserNode laserNode = (ILaserNode) obj;
                            if (this.canConnectTo(laserNode) && laserNode.canConnectTo(this)) {
                                this.addNode(laserNode);
                                laserNode.addNode(this);
                            }
                        }
                    }
                }
            }
        }
    }
    this.setTarget(this.nodeList.peekFirst());
}
Also used : ILaserNode(micdoodle8.mods.galacticraft.api.power.ILaserNode) Chunk(net.minecraft.world.chunk.Chunk) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Aggregations

BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)104 TileEntity (net.minecraft.tileentity.TileEntity)44 EnumFacing (net.minecraft.util.EnumFacing)20 IBlockState (net.minecraft.block.state.IBlockState)14 BlockPos (net.minecraft.util.BlockPos)13 World (net.minecraft.world.World)10 IPartialSealableBlock (micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock)9 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)9 Block (net.minecraft.block.Block)9 ArrayList (java.util.ArrayList)7 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)7 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)7 NBTTagList (net.minecraft.nbt.NBTTagList)7 IConductor (micdoodle8.mods.galacticraft.api.transmission.tile.IConductor)6 TileEntityOxygenSealer (micdoodle8.mods.galacticraft.core.tile.TileEntityOxygenSealer)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 Entity (net.minecraft.entity.Entity)5 LinkedList (java.util.LinkedList)4 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)4 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)4