Search in sources :

Example 11 with BlockVec3

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

the class TileEntityBeamReceiver method getAttachedTile.

public TileEntity getAttachedTile() {
    if (this.facing == null) {
        return null;
    }
    TileEntity tile = new BlockVec3(this).getTileEntityOnSide(this.worldObj, this.facing);
    if (tile == null || tile.isInvalid()) {
        this.setFacing(null);
    }
    if (tile instanceof IConductor) {
        this.setFacing(null);
        return null;
    }
    if (tile instanceof EnergyStorageTile) {
        EnergyStorage attachedStorage = ((EnergyStorageTile) tile).storage;
        this.storage.setCapacity(attachedStorage.getCapacityGC() - attachedStorage.getEnergyStoredGC());
        this.storage.setMaxExtract(attachedStorage.getMaxExtract());
        this.storage.setMaxReceive(attachedStorage.getMaxReceive());
    }
    return tile;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 12 with BlockVec3

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

the class TileEntityBeamOutput method addNode.

@Override
public void addNode(ILaserNode node) {
    int index = -1;
    for (int i = 0; i < this.nodeList.size(); i++) {
        if (new BlockVec3(this.nodeList.get(i).getTile()).equals(new BlockVec3(node.getTile()))) {
            index = i;
            break;
        }
    }
    if (index != -1) {
        this.nodeList.set(index, node);
        return;
    }
    if (this.nodeList.isEmpty()) {
        this.nodeList.add(node);
    } else {
        int nodeCompare = this.nodeList.get(0).compareTo(node, new BlockVec3(this));
        if (nodeCompare <= 0) {
            this.nodeList.addFirst(node);
            return;
        }
        nodeCompare = this.nodeList.get(this.nodeList.size() - 1).compareTo(node, new BlockVec3(this));
        if (nodeCompare >= 0) {
            this.nodeList.addLast(node);
            return;
        }
        index = 1;
        while (index < this.nodeList.size()) {
            index++;
        }
        this.nodeList.add(index, node);
    }
}
Also used : BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 13 with BlockVec3

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

the class TileEntityElectrolyzer method produceOxygen.

private boolean produceOxygen(EnumFacing outputDirection) {
    int provide = this.getOxygenProvide(outputDirection);
    if (provide > 0) {
        TileEntity outputTile = new BlockVec3(this).modifyPositionFromSide(outputDirection).getTileEntity(this.worldObj);
        FluidNetwork outputNetwork = NetworkHelper.getFluidNetworkFromTile(outputTile, outputDirection);
        if (outputNetwork != null) {
            int gasRequested = outputNetwork.getRequest();
            if (gasRequested > 0) {
                int usedGas = outputNetwork.emitToBuffer(new FluidStack(GCFluids.fluidOxygenGas, Math.min(gasRequested, provide)), true);
                this.drawOxygen(usedGas, true);
                return true;
            }
        } else if (outputTile instanceof IOxygenReceiver) {
            float requestedOxygen = ((IOxygenReceiver) outputTile).getOxygenRequest(outputDirection.getOpposite());
            if (requestedOxygen > 0) {
                int toSend = Math.min(this.getOxygenStored(), provide);
                int acceptedOxygen = ((IOxygenReceiver) outputTile).receiveOxygen(outputDirection.getOpposite(), toSend, true);
                this.drawOxygen(acceptedOxygen, true);
                return true;
            }
        }
    // else if (EnergyConfigHandler.isMekanismLoaded())
    // {
    // //TODO Oxygen item handling - internal tank (IGasItem)
    // //int acceptedOxygen = GasTransmission.addGas(itemStack, type, amount);
    // //this.drawOxygen(acceptedOxygen, true);
    // 
    // if (outputTile instanceof IGasHandler && ((IGasHandler) outputTile).canReceiveGas(outputDirection.getOpposite(), (Gas) EnergyConfigHandler.gasOxygen))
    // {
    // GasStack toSend = new GasStack((Gas) EnergyConfigHandler.gasOxygen, (int) Math.floor(Math.min(this.getOxygenStored(), provide)));
    // int acceptedOxygen = 0;
    // try {
    // acceptedOxygen = ((IGasHandler) outputTile).receiveGas(outputDirection.getOpposite(), toSend);
    // } catch (Exception e) { }
    // this.drawOxygen(acceptedOxygen, true);
    // return true;
    // }
    // }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) IOxygenReceiver(micdoodle8.mods.galacticraft.api.transmission.tile.IOxygenReceiver) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 14 with BlockVec3

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

the class EnergyNetwork method split.

@Override
public void split(IConductor splitPoint) {
    if (splitPoint instanceof TileEntity) {
        this.getTransmitters().remove(splitPoint);
        splitPoint.setNetwork(null);
        // If the size of the residual network is 1, it should simply be preserved
        if (this.getTransmitters().size() > 1) {
            World world = ((TileEntity) splitPoint).getWorld();
            if (this.getTransmitters().size() > 0) {
                TileEntity[] nextToSplit = new TileEntity[6];
                boolean[] toDo = { true, true, true, true, true, true };
                TileEntity tileEntity;
                int xCoord = ((TileEntity) splitPoint).getPos().getX();
                int yCoord = ((TileEntity) splitPoint).getPos().getY();
                int zCoord = ((TileEntity) splitPoint).getPos().getZ();
                for (int j = 0; j < 6; j++) {
                    switch(j) {
                        case 0:
                            tileEntity = world.getTileEntity(((TileEntity) splitPoint).getPos().down());
                            break;
                        case 1:
                            tileEntity = world.getTileEntity(((TileEntity) splitPoint).getPos().up());
                            break;
                        case 2:
                            tileEntity = world.getTileEntity(((TileEntity) splitPoint).getPos().north());
                            break;
                        case 3:
                            tileEntity = world.getTileEntity(((TileEntity) splitPoint).getPos().south());
                            break;
                        case 4:
                            tileEntity = world.getTileEntity(((TileEntity) splitPoint).getPos().west());
                            break;
                        case 5:
                            tileEntity = world.getTileEntity(((TileEntity) splitPoint).getPos().east());
                            break;
                        default:
                            // Not reachable, only to prevent uninitiated compile errors
                            tileEntity = null;
                            break;
                    }
                    if (tileEntity instanceof IConductor) {
                        nextToSplit[j] = tileEntity;
                    } else {
                        toDo[j] = false;
                    }
                }
                for (int i1 = 0; i1 < 6; i1++) {
                    if (toDo[i1]) {
                        TileEntity connectedBlockA = nextToSplit[i1];
                        NetworkFinder finder = new NetworkFinder(world, new BlockVec3(connectedBlockA), new BlockVec3((TileEntity) splitPoint));
                        List<IConductor> partNetwork = finder.exploreNetwork();
                        // Mark any others still to do in the nextToSplit array which are connected to this, as dealt with
                        for (int i2 = i1 + 1; i2 < 6; i2++) {
                            TileEntity connectedBlockB = nextToSplit[i2];
                            if (toDo[i2]) {
                                if (partNetwork.contains(connectedBlockB)) {
                                    toDo[i2] = false;
                                }
                            }
                        }
                        // Now make the new network from partNetwork
                        EnergyNetwork newNetwork = new EnergyNetwork();
                        newNetwork.getTransmitters().addAll(partNetwork);
                        newNetwork.refreshWithChecks();
                    }
                }
                this.destroy();
            }
        } else // Splitting a 1-block network leaves nothing
        if (this.getTransmitters().size() == 0) {
            this.destroy();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) World(net.minecraft.world.World) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 15 with BlockVec3

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

the class EnergyUtil method setAdjacentPowerConnections.

/**
 * Similar to getAdjacentPowerConnections but specific to energy receivers only
 * Adds the adjacent power connections found to the passed acceptors, directions parameter Lists
 * (Note: an acceptor can therefore sometimes be entered in the Lists more than once, with a different direction each time:
 * this would represent GC wires connected to the acceptor on more than one side.)
 *
 * @param conductor
 * @param connectedAcceptors
 * @param directions
 * @throws Exception
 */
public static void setAdjacentPowerConnections(TileEntity conductor, List<Object> connectedAcceptors, List<EnumFacing> directions) throws Exception {
    final BlockVec3 thisVec = new BlockVec3(conductor);
    final World world = conductor.getWorld();
    for (EnumFacing direction : EnumFacing.VALUES) {
        TileEntity tileEntity = thisVec.getTileEntityOnSide(world, direction);
        if (// world.getTileEntity will not have returned an invalid tile, invalid tiles are null
        tileEntity == null || tileEntity instanceof IConductor) {
            continue;
        }
        EnumFacing sideFrom = direction.getOpposite();
        if (tileEntity instanceof IElectrical) {
            if (((IElectrical) tileEntity).canConnect(sideFrom, NetworkType.POWER)) {
                connectedAcceptors.add(tileEntity);
                directions.add(sideFrom);
            }
            continue;
        }
        if (isMekLoaded && tileEntity instanceof IStrictEnergyAcceptor) {
            if (clazzMekCable != null && clazzMekCable.isInstance(tileEntity)) {
                continue;
            }
            if (((IStrictEnergyAcceptor) tileEntity).canReceiveEnergy(sideFrom)) {
                connectedAcceptors.add(tileEntity);
                directions.add(sideFrom);
            }
            continue;
        }
        if (isBCReallyLoaded && clazzPipeTile.isInstance(tileEntity)) {
            continue;
        }
        if (isIC2Loaded && !world.isRemote) {
            IEnergyTile IC2tile = null;
            BlockPos checkingIC2 = thisVec.toBlockPos().offset(direction);
            try {
                IC2tile = EnergyNet.instance.getSubTile(world, checkingIC2);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (IC2tile instanceof IEnergyConductor) {
                continue;
            }
            if (IC2tile instanceof IEnergyAcceptor && ((IEnergyAcceptor) IC2tile).acceptsEnergyFrom((IEnergyEmitter) conductor, sideFrom)) {
                connectedAcceptors.add(IC2tile);
                directions.add(sideFrom);
            }
            continue;
        }
        if ((isRF2Loaded && tileEntity instanceof IEnergyReceiver) || (isRF1Loaded && tileEntity instanceof IEnergyHandler)) {
            if (clazzEnderIOCable != null && clazzEnderIOCable.isInstance(tileEntity)) {
                continue;
            }
            if (clazzMFRRednetEnergyCable != null && clazzMFRRednetEnergyCable.isInstance(tileEntity)) {
                continue;
            }
            if (((IEnergyConnection) tileEntity).canConnectEnergy(sideFrom)) {
                connectedAcceptors.add(tileEntity);
                directions.add(sideFrom);
            }
            continue;
        }
    }
    return;
}
Also used : IEnergyConnection(cofh.api.energy.IEnergyConnection) EnumFacing(net.minecraft.util.EnumFacing) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) IStrictEnergyAcceptor(mekanism.api.energy.IStrictEnergyAcceptor) IEnergyHandler(cofh.api.energy.IEnergyHandler) BlockPos(net.minecraft.util.BlockPos) IElectrical(micdoodle8.mods.galacticraft.api.transmission.tile.IElectrical) IEnergyReceiver(cofh.api.energy.IEnergyReceiver) 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