Search in sources :

Example 1 with CoordTuple

use of minechem.utils.CoordTuple in project Minechem by iopleke.

the class PolytoolTypeIron method onBlockDestroyed.

@Override
public void onBlockDestroyed(ItemStack itemStack, World world, Block id, int x1, int y1, int z1, EntityLivingBase entityLiving) {
    if (!world.isRemote && entityLiving instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entityLiving;
        ArrayList<CoordTuple> queue = new ArrayList<CoordTuple>(100);
        float carbon = 0;
        for (Object upgrade : PolytoolItem.getUpgrades(itemStack)) {
            if (((PolytoolUpgradeType) upgrade).getElement() == ElementEnum.C) {
                carbon = ((PolytoolUpgradeType) upgrade).power;
            }
        }
        int meta = world.getBlockMetadata(x1, y1, z1);
        if (ores.containsKey(blockHash(id, meta))) {
            int toMine = (int) power;
            queue.add(new CoordTuple(x1, y1, z1));
            while (!queue.isEmpty()) {
                CoordTuple coord = queue.remove(0);
                int x = coord.x;
                int y = coord.y;
                int z = coord.z;
                for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                    if (world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ) == id && world.getBlockMetadata(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ) == meta) {
                        breakExtraBlock(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, player, id, meta, carbon);
                        queue.add(new CoordTuple(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ));
                        toMine--;
                        if (toMine <= 0) {
                            return;
                        }
                    }
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CoordTuple(minechem.utils.CoordTuple)

Example 2 with CoordTuple

use of minechem.utils.CoordTuple in project Minechem by iopleke.

the class ChemicalFluidReactionHandler method chemicalReaction.

private static void chemicalReaction(World world, Entity entity, int x, int y, int z, ChemicalFluidReactionRule rule, boolean popFlowingFluid) {
    ChemicalFluidReactionOutput output = reactionRules.get(rule);
    if (output == null) {
        return;
    }
    if (!Float.isNaN(output.explosionLevel)) {
        world.createExplosion(null, x, y, z, output.explosionLevel, true);
    }
    int halfSpace = FLUIDS_GENERATE_SPACE / 2;
    List[] availableSpaces = new List[FLUIDS_GENERATE_SPACE];
    for (int i = 0; i < availableSpaces.length; i++) {
        availableSpaces[i] = findAvailableSpacesAtCrossSection(world, x, y - halfSpace + i, z, 1);
    }
    Iterator<MinechemChemicalType> it = output.outputs.iterator();
    while (it.hasNext()) {
        MinechemChemicalType chemical = it.next();
        boolean hasFlowingStatus = chemical.roomState().getQuanta() > 2;
        CoordTuple coords = null;
        if (!(!hasFlowingStatus && popFlowingFluid)) {
            boolean isGas = chemical.roomState().isGas();
            if (isGas) {
                for (int i = availableSpaces.length - 1; i > -1; i--) {
                    if (!availableSpaces[i].isEmpty()) {
                        coords = (CoordTuple) availableSpaces[i].remove(availableSpaces[i].size() - 1);
                        break;
                    }
                }
            } else {
                for (int i = 0; i < availableSpaces.length; i++) {
                    if (!availableSpaces[i].isEmpty()) {
                        coords = (CoordTuple) availableSpaces[i].remove(availableSpaces[i].size() - 1);
                        break;
                    }
                }
            }
        }
        if (coords == null) {
            if (!popFlowingFluid) {
                ItemStack itemStack = MinechemUtil.createItemStack(chemical, 8);
                MinechemUtil.throwItemStack(world, itemStack, x, y, z);
            }
        } else if (!(popFlowingFluid && !hasFlowingStatus)) {
            int px = coords.getX();
            int py = coords.getY();
            int pz = coords.getZ();
            world.func_147480_a(px, py, pz, true);
            world.setBlockToAir(px, py, pz);
            Block fluidBlock = null;
            if (chemical instanceof ElementEnum) {
                fluidBlock = FluidHelper.elementsBlocks.get(FluidHelper.elements.get(chemical));
            } else if (chemical instanceof MoleculeEnum) {
                fluidBlock = FluidHelper.moleculeBlocks.get(FluidHelper.molecules.get(chemical));
            }
            if (fluidBlock != null) {
                world.setBlock(px, py, pz, fluidBlock, popFlowingFluid ? 1 : 0, 3);
            }
        }
    }
}
Also used : ElementEnum(minechem.item.element.ElementEnum) Block(net.minecraft.block.Block) MinechemFluidBlock(minechem.fluid.MinechemFluidBlock) ArrayList(java.util.ArrayList) List(java.util.List) CoordTuple(minechem.utils.CoordTuple) MoleculeEnum(minechem.item.molecule.MoleculeEnum) ItemStack(net.minecraft.item.ItemStack) MinechemChemicalType(minechem.item.MinechemChemicalType)

Example 3 with CoordTuple

use of minechem.utils.CoordTuple in project Minechem by iopleke.

the class ChemicalFluidReactionHandler method findAvailableSpacesAtCrossSection.

public static List<CoordTuple> findAvailableSpacesAtCrossSection(World world, int centerX, int centerY, int centerZ, int size) {
    List<CoordTuple> spaces = new ArrayList<CoordTuple>();
    for (int xOffset = -size; xOffset <= size; xOffset++) {
        for (int zOffset = -size; zOffset <= size; zOffset++) {
            int x = centerX + xOffset;
            int z = centerZ + zOffset;
            if (world.isAirBlock(x, centerY, z) || !world.getBlock(x, centerY, z).getMaterial().isSolid()) {
                spaces.add(new CoordTuple(x, centerY, z));
            }
        }
    }
    return spaces;
}
Also used : ArrayList(java.util.ArrayList) CoordTuple(minechem.utils.CoordTuple)

Aggregations

ArrayList (java.util.ArrayList)3 CoordTuple (minechem.utils.CoordTuple)3 List (java.util.List)1 MinechemFluidBlock (minechem.fluid.MinechemFluidBlock)1 MinechemChemicalType (minechem.item.MinechemChemicalType)1 ElementEnum (minechem.item.element.ElementEnum)1 MoleculeEnum (minechem.item.molecule.MoleculeEnum)1 Block (net.minecraft.block.Block)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1