use of micdoodle8.mods.galacticraft.api.transmission.tile.IConductor 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;
}
use of micdoodle8.mods.galacticraft.api.transmission.tile.IConductor in project Galacticraft by micdoodle8.
the class EnergyNetwork method refresh.
@Override
public void refresh() {
int tierfound = Integer.MAX_VALUE;
Iterator<IConductor> it = this.conductors.iterator();
while (it.hasNext()) {
IConductor conductor = it.next();
if (conductor == null) {
it.remove();
continue;
}
TileEntity tile = (TileEntity) conductor;
World world = tile.getWorld();
// Remove any conductors in unloaded chunks
if (tile.isInvalid() || world == null) {
it.remove();
continue;
}
if (conductor.getTierGC() < tierfound) {
tierfound = conductor.getTierGC();
}
if (conductor.getNetwork() != this) {
conductor.setNetwork(this);
conductor.onNetworkChanged();
}
}
// This will set the network tier to 2 if all the conductors are tier 2, etc
if (tierfound == Integer.MAX_VALUE) {
tierfound = 1;
}
this.networkTierGC = tierfound;
}
use of micdoodle8.mods.galacticraft.api.transmission.tile.IConductor 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();
}
}
}
use of micdoodle8.mods.galacticraft.api.transmission.tile.IConductor 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;
}
use of micdoodle8.mods.galacticraft.api.transmission.tile.IConductor in project Galacticraft by micdoodle8.
the class BlockEnclosed method onNeighborBlockChange.
@Override
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block block) {
int metadata = state.getBlock().getMetaFromState(state);
final TileEntity tileEntity = world.getTileEntity(pos);
if (metadata == EnumEnclosedBlockType.TE_CONDUIT.getMeta()) {
super.onNeighborBlockChange(world, pos, state, block);
} else if (metadata == EnumEnclosedBlockType.OXYGEN_PIPE.getMeta()) {
super.onNeighborBlockChange(world, pos, state, block);
if (tileEntity instanceof INetworkConnection) {
((INetworkConnection) tileEntity).refresh();
}
} else if (metadata <= 6) {
super.onNeighborBlockChange(world, pos, state, block);
if (CompatibilityManager.isIc2Loaded() && tileEntity != null) {
try {
if (onBlockNeighbourChangeIC2a != null) {
onBlockNeighbourChangeIC2a.invoke(tileEntity, block);
} else if (onBlockNeighbourChangeIC2b != null) {
onBlockNeighbourChangeIC2b.invoke(tileEntity, block, pos);
}
return;
} catch (Exception ignore) {
}
}
} else if (metadata <= 12) {
if (CompatibilityManager.isBCraftTransportLoaded()) {
if (blockPipeBC != null) {
try {
blockPipeBC.onNeighborBlockChange(world, pos, state, block);
} catch (Exception e) {
e.printStackTrace();
}
return;
}
}
super.onNeighborBlockChange(world, pos, state, block);
} else if (metadata <= EnumEnclosedBlockType.ME_CABLE.getMeta()) {
super.onNeighborBlockChange(world, pos, state, block);
if (CompatibilityManager.isAppEngLoaded()) {
world.markBlockForUpdate(pos);
}
} else if (metadata <= EnumEnclosedBlockType.ALUMINUM_WIRE.getMeta()) {
super.onNeighborBlockChange(world, pos, state, block);
if (tileEntity instanceof IConductor) {
((IConductor) tileEntity).refresh();
}
} else if (metadata <= EnumEnclosedBlockType.ALUMINUM_WIRE_HEAVY.getMeta()) {
super.onNeighborBlockChange(world, pos, state, block);
if (tileEntity instanceof IConductor) {
((IConductor) tileEntity).refresh();
}
}
}
Aggregations