Search in sources :

Example 16 with BlockVec3

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

the class EventHandlerGC method generateOil.

/**
 * xx, zz are the central position of 4 chunks: the chunk currently being populated + 1 in the x,z plane
 * We must not stray more than 1 chunk away from this position, that's 16 blocks
 */
public static void generateOil(World world, Random rand, int xx, int zz, boolean testFirst) {
    BlockVec3 pos = new BlockVec3();
    if (oilPresent(world, rand, xx, zz, pos)) {
        int x = pos.x;
        int cy = pos.y;
        int z = pos.z;
        int r = 3 + rand.nextInt(5);
        if (testFirst && checkOilPresent(world, x, cy, z, r)) {
            return;
        }
        final int r2 = r * r;
        IBlockState crudeOil = GCBlocks.crudeOil.getDefaultState();
        for (int bx = -r; bx <= r; bx++) {
            for (int by = -r + 2; by <= r - 2; by++) {
                int xySquared = bx * bx + by * by * 3;
                for (int bz = -r; bz <= r; bz++) {
                    if (xySquared + bz * bz <= r2) {
                        if (EventHandlerGC.checkBlock(world, new BlockPos(bx + x - 1, by + cy, bz + z))) {
                            continue;
                        }
                        if (EventHandlerGC.checkBlock(world, new BlockPos(bx + x + 1, by + cy, bz + z))) {
                            continue;
                        }
                        if (EventHandlerGC.checkBlock(world, new BlockPos(bx + x, by + cy - 1, bz + z))) {
                            continue;
                        }
                        if (EventHandlerGC.checkBlock(world, new BlockPos(bx + x, by + cy, bz + z - 1))) {
                            continue;
                        }
                        if (EventHandlerGC.checkBlock(world, new BlockPos(bx + x, by + cy, bz + z + 1))) {
                            continue;
                        }
                        if (EventHandlerGC.checkBlockAbove(world, new BlockPos(bx + x, by + cy + 1, bz + z))) {
                            continue;
                        }
                        world.setBlockState(new BlockPos(bx + x, by + cy, bz + z), crudeOil, 2);
                    }
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 17 with BlockVec3

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

the class NetworkHelper method getNetworksFromMultipleSides.

/**
 * @param tileEntity           - The TileEntity's sides.
 * @param approachingDirection - The directions that can be connected.
 * @return A list of networks from all specified sides. There will be no
 * repeated ElectricityNetworks and it will never return null.
 */
public static Set<IElectricityNetwork> getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet<EnumFacing> approachingDirection) {
    final Set<IElectricityNetwork> connectedNetworks = new HashSet<IElectricityNetwork>();
    BlockVec3 tileVec = new BlockVec3(tileEntity);
    for (EnumFacing side : EnumFacing.VALUES) {
        if (approachingDirection.contains(side)) {
            TileEntity outputConductor = tileVec.getTileEntityOnSide(tileEntity.getWorld(), side);
            IElectricityNetwork electricityNetwork = NetworkHelper.getElectricalNetworkFromTileEntity(outputConductor, side);
            if (electricityNetwork != null) {
                connectedNetworks.add(electricityNetwork);
            }
        }
    }
    return connectedNetworks;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IElectricityNetwork(micdoodle8.mods.galacticraft.api.transmission.grid.IElectricityNetwork) HashSet(java.util.HashSet) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 18 with BlockVec3

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

the class ThreadFindSeal method checkedContainsTrace.

private BlockVec3 checkedContainsTrace(int x, int y, int z) {
    int dx = this.head.x - x;
    int dz = this.head.z - z;
    if (dx < -8191 || dx > 8192)
        return null;
    if (dz < -8191 || dz > 8192)
        return null;
    intBucket bucket = buckets[((dx & 15) << 4) + (dz & 15)];
    int side = bucket.getMSB4shifted(y + ((dx & 0x3FF0) + ((dz & 0x3FF0) << 10) << 4));
    if (side >= 0) {
        BlockVec3 vec = new BlockVec3(x, y, z);
        vec.sideDoneBits = side;
        return vec;
    }
    return null;
}
Also used : BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 19 with BlockVec3

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

the class ThreadFindSeal method doLayer.

private void doLayer() {
    // Local variables are fractionally faster than statics
    Block breatheableAirID = GCBlocks.breatheableAir;
    Block airID = Blocks.air;
    Block breatheableAirIDBright = GCBlocks.brightBreatheableAir;
    Block airIDBright = GCBlocks.brightAir;
    Block oxygenSealerID = GCBlocks.oxygenSealer;
    LinkedList<BlockVec3> nextLayer = new LinkedList<>();
    World world = this.world;
    int side, bits;
    while (this.sealed && this.currentLayer.size() > 0) {
        for (BlockVec3 vec : this.currentLayer) {
            // This is for side = 0 to 5 - but using do...while() is fractionally quicker
            side = 0;
            bits = vec.sideDoneBits;
            do {
                // This is also used to skip looking on the solid sides of partially sealable blocks
                if ((bits & (1 << side)) == 0) {
                    if (!checkedContains(vec, side)) {
                        BlockVec3 sideVec = vec.newVecSide(side);
                        if (this.checkCount > 0) {
                            this.checkCount--;
                            Block id = sideVec.getBlockIDsafe_noChunkLoad(world);
                            // The most likely case
                            if (id == breatheableAirID) {
                                checkedAdd(sideVec);
                                nextLayer.add(sideVec);
                                this.ambientThermalTracked.add(sideVec);
                            } else if (id == airID) {
                                checkedAdd(sideVec);
                                nextLayer.add(sideVec);
                                this.airToReplace.add(sideVec);
                            } else if (id == breatheableAirIDBright) {
                                checkedAdd(sideVec);
                                nextLayer.add(sideVec);
                                this.ambientThermalTrackedBright.add(sideVec);
                            } else if (id == airIDBright) {
                                checkedAdd(sideVec);
                                nextLayer.add(sideVec);
                                this.airToReplaceBright.add(sideVec);
                            } else if (id == null) {
                                // Broken through to the void or the
                                // stratosphere (above y==255) - set
                                // unsealed and abort
                                this.checkCount = 0;
                                this.sealed = false;
                                return;
                            } else if (id == oxygenSealerID) {
                                TileEntityOxygenSealer sealer = this.sealersAround.get(sideVec);
                                if (sealer != null && !this.sealers.contains(sealer)) {
                                    if (side == 0) {
                                        checkedAdd(sideVec);
                                        this.sealers.add(sealer);
                                        if (sealer.thermalControlEnabled()) {
                                            foundAmbientThermal = true;
                                        }
                                        this.checkCount += sealer.getFindSealChecks();
                                    }
                                // if side != 0, no checkedAdd() - allows this sealer to be checked again from other sides
                                }
                            } else if (this.canBlockPassAirCheck(id, sideVec, side)) {
                                nextLayer.add(sideVec);
                            }
                        // If the chunk was unloaded, BlockVec3.getBlockID returns Blocks.bedrock
                        // which is a solid block, so the loop will treat that as a sealed edge
                        // and not iterate any further in that direction
                        } else // the if (this.isSealed) check here is unnecessary because of the returns
                        {
                            Block id = sideVec.getBlockIDsafe_noChunkLoad(this.world);
                            // of which are unsealed obviously
                            if (id == null || id == airID || id == breatheableAirID || id == airIDBright || id == breatheableAirIDBright || this.canBlockPassAirCheck(id, sideVec, side)) {
                                this.sealed = false;
                                if (this.sealers.size() > 0) {
                                    vec.sideDoneBits = side << 6;
                                    traceLeak(vec);
                                }
                                return;
                            }
                        }
                    }
                }
                side++;
            } while (side < 6);
        }
        // Is there a further layer of air/permeable blocks to test?
        this.currentLayer = nextLayer;
        nextLayer = new LinkedList<BlockVec3>();
    }
}
Also used : TileEntityOxygenSealer(micdoodle8.mods.galacticraft.core.tile.TileEntityOxygenSealer) IPartialSealableBlock(micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock) World(net.minecraft.world.World) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 20 with BlockVec3

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

the class ThreadFindSeal method canBlockPassAirCheck.

private boolean canBlockPassAirCheck(Block block, BlockVec3 vec, int side) {
    if (block instanceof IPartialSealableBlock) {
        EnumFacing testSide = EnumFacing.getFront(side);
        IPartialSealableBlock blockPartial = (IPartialSealableBlock) block;
        BlockPos vecPos = new BlockPos(vec.x, vec.y, vec.z);
        if (blockPartial.isSealed(this.world, vecPos, testSide)) {
            // If a partial block checks as solid, allow it to be tested
            // again from other directions
            // This won't cause an endless loop, because the block won't
            // be included in nextLayer if it checks as solid
            this.checkCount--;
            return false;
        }
        // Find the solid sides so they don't get iterated into, when doing the next layer
        for (EnumFacing face : EnumFacing.VALUES) {
            if (face == testSide) {
                continue;
            }
            if (blockPartial.isSealed(this.world, vecPos, face)) {
                vec.setSideDone(face.getIndex() ^ 1);
            }
        }
        checkedAdd(vec);
        return true;
    }
    // (See net.minecraft.block.BlockLeaves.isOpaqueCube()!)
    if (block instanceof BlockLeavesBase) {
        checkedAdd(vec);
        return true;
    }
    if (block.isOpaqueCube()) {
        checkedAdd(vec);
        // Gravel, wool and sponge are porous
        return block instanceof BlockGravel || block.getMaterial() == Material.cloth || block instanceof BlockSponge;
    }
    if (block instanceof BlockGlass || block instanceof BlockStainedGlass) {
        checkedAdd(vec);
        return false;
    }
    // Solid but non-opaque blocks, for example special glass
    if (OxygenPressureProtocol.nonPermeableBlocks.containsKey(block)) {
        ArrayList<Integer> metaList = OxygenPressureProtocol.nonPermeableBlocks.get(block);
        if (metaList.contains(Integer.valueOf(-1)) || metaList.contains(vec.getBlockMetadata(this.world))) {
            checkedAdd(vec);
            return false;
        }
    }
    if (block instanceof BlockUnlitTorch) {
        this.torchesToUpdate.add(vec);
        checkedAdd(vec);
        return true;
    }
    // Half slab seals on the top side or the bottom side according to its metadata
    if (block instanceof BlockSlab) {
        boolean isTopSlab = (vec.getBlockMetadata(this.world) & 8) == 8;
        // Looking down onto a top slab or looking up onto a bottom slab
        if (side == 0 && isTopSlab || side == 1 && !isTopSlab) {
            // Sealed from that solid side but allow other sides still to be checked
            this.checkCount--;
            return false;
        }
        // Not sealed
        vec.setSideDone(isTopSlab ? 1 : 0);
        checkedAdd(vec);
        return true;
    }
    // Farmland etc only seals on the solid underside
    if (block instanceof BlockFarmland || block instanceof BlockEnchantmentTable || block instanceof BlockLiquid) {
        if (side == 1) {
            // Sealed from the underside but allow other sides still to be checked
            this.checkCount--;
            return false;
        }
        // Not sealed
        vec.setSideDone(0);
        checkedAdd(vec);
        return true;
    }
    if (block instanceof BlockPistonBase) {
        BlockPistonBase piston = (BlockPistonBase) block;
        IBlockState state = this.world.getBlockState(new BlockPos(vec.x, vec.y, vec.z));
        if (((Boolean) state.getValue(BlockPistonBase.EXTENDED)).booleanValue()) {
            int facing = ((EnumFacing) state.getValue(BlockPistonBase.FACING)).getIndex();
            if (side == facing) {
                this.checkCount--;
                return false;
            }
            vec.setSideDone(facing ^ 1);
            checkedAdd(vec);
            return true;
        }
        checkedAdd(vec);
        return false;
    }
    // ### Any exceptions in mods should implement the IPartialSealableBlock interface ###
    if (block.isSideSolid(this.world, new BlockPos(vec.x, vec.y, vec.z), EnumFacing.getFront(side ^ 1))) {
        // Solid on all sides
        if (block.getMaterial().blocksMovement() && block.isFullCube()) {
            checkedAdd(vec);
            return false;
        }
        // Sealed from this side but allow other sides still to be checked
        this.checkCount--;
        return false;
    }
    // Easy case: airblock, return without checking other sides
    if (block.getMaterial() == Material.air) {
        checkedAdd(vec);
        return true;
    }
    // Look to see if there is any other side which is solid in which case a check will not be needed next time
    for (int i = 0; i < 6; i++) {
        if (i == (side ^ 1)) {
            continue;
        }
        if (block.isSideSolid(this.world, new BlockPos(vec.x, vec.y, vec.z), EnumFacing.getFront(i))) {
            vec.setSideDone(i);
        }
    }
    // Not solid from this side, so this is not sealed
    checkedAdd(vec);
    return true;
}
Also used : IPartialSealableBlock(micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockUnlitTorch(micdoodle8.mods.galacticraft.core.blocks.BlockUnlitTorch) BlockPos(net.minecraft.util.BlockPos) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

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