use of micdoodle8.mods.galacticraft.planets.venus.tile.SolarModuleNetwork in project Galacticraft by micdoodle8.
the class TileEntitySolarArrayController method update.
@Override
public void update() {
if (!this.initialised) {
this.storage.setCapacity(50000);
this.initialised = true;
}
if (!this.world.isRemote) {
this.receiveEnergyGC(null, this.generateWatts, false);
EnumSet<EnumFacing> outputDirections = EnumSet.noneOf(EnumFacing.class);
outputDirections.addAll(Arrays.asList(EnumFacing.HORIZONTALS));
outputDirections.removeAll(this.getElectricalOutputDirections());
BlockVec3 thisVec = new BlockVec3(this);
solarArray.clear();
for (EnumFacing direction : outputDirections) {
TileEntity tileAdj = thisVec.getTileEntityOnSide(this.world, direction);
if (tileAdj != null) {
if (tileAdj instanceof INetworkProvider) {
if (tileAdj instanceof ITransmitter) {
if (((ITransmitter) tileAdj).canConnect(direction.getOpposite(), NetworkType.SOLAR_MODULE)) {
if (((INetworkProvider) tileAdj).getNetwork() instanceof SolarModuleNetwork) {
solarArray.addAll(((SolarModuleNetwork) ((INetworkProvider) tileAdj).getNetwork()).getTransmitters());
}
}
} else {
if (((INetworkProvider) tileAdj).getNetwork() instanceof SolarModuleNetwork) {
solarArray.addAll(((SolarModuleNetwork) ((INetworkProvider) tileAdj).getNetwork()).getTransmitters());
}
}
}
}
}
}
super.update();
if (!this.world.isRemote) {
this.recharge(this.getInventory().get(0));
if (this.disableCooldown > 0) {
this.disableCooldown--;
}
if (!this.getDisabled(0) && this.ticks % 20 == 0) {
this.solarStrength = 0;
int arraySizeWithinRange = 0;
if (this.world.isDaytime() && (this.world.provider instanceof IGalacticraftWorldProvider || !this.world.isRaining() && !this.world.isThundering())) {
for (ITransmitter transmitter : solarArray) {
TileEntity tile = (TileEntity) transmitter;
Vec3i diff = tile.getPos().subtract(this.getPos());
if (Math.abs(diff.getX()) <= 16 && diff.getY() == 0 && Math.abs(diff.getZ()) <= 16) {
arraySizeWithinRange++;
if (this.world.canBlockSeeSky(tile.getPos())) {
boolean valid = true;
for (int y = this.getPos().getY() + 1; y < 256; y++) {
IBlockState state = this.world.getBlockState(this.getPos().add(0, y, 0));
if (state.getBlock().isOpaqueCube(state)) {
valid = false;
break;
}
}
if (valid) {
this.solarStrength++;
}
}
}
}
}
connectedInfo = solarStrength << 16 | arraySizeWithinRange;
}
}
float angle = this.world.getCelestialAngle(1.0F) - 0.7845194F < 0 ? 1.0F - 0.7845194F : -0.7845194F;
float celestialAngle = (this.world.getCelestialAngle(1.0F) + angle) * 360.0F;
if (!(this.world.provider instanceof WorldProviderSpaceStation))
celestialAngle += 12.5F;
if (this.world.provider instanceof WorldProviderVenus)
celestialAngle = 180F - celestialAngle;
celestialAngle %= 360;
boolean isDaytime = this.world.isDaytime() && (celestialAngle < 180.5F || celestialAngle > 359.5F) || this.world.provider instanceof WorldProviderSpaceStation;
if (!this.world.isRemote) {
int generated = this.getGenerate();
if (generated > 0) {
this.generateWatts = Math.min(Math.max(generated, 0), TileEntitySolarArrayController.MAX_GENERATE_WATTS);
} else {
this.generateWatts = 0;
}
}
this.produce();
}
use of micdoodle8.mods.galacticraft.planets.venus.tile.SolarModuleNetwork in project Galacticraft by micdoodle8.
the class TileEntitySolarTransmitter method refresh.
@Override
public void refresh() {
if (!this.world.isRemote) {
this.adjacentConnections = null;
BlockVec3 thisVec = new BlockVec3(this);
for (EnumFacing side : EnumFacing.VALUES) {
TileEntity tileEntity = thisVec.getTileEntityOnSide(this.world, side);
if (tileEntity != null) {
if (tileEntity.getClass() == this.getClass() && tileEntity instanceof INetworkProvider && ((INetworkProvider) tileEntity).hasNetwork()) {
if (!(tileEntity instanceof ITransmitter) || (((ITransmitter) tileEntity).canConnect(side.getOpposite(), ((ITransmitter) tileEntity).getNetworkType()))) {
if (!this.hasNetwork()) {
this.setNetwork(((INetworkProvider) tileEntity).getNetwork());
((SolarModuleNetwork) this.getNetwork()).addTransmitter(this);
} else if (this.hasNetwork() && !this.getNetwork().equals(((INetworkProvider) tileEntity).getNetwork())) {
this.setNetwork((IGridNetwork) this.getNetwork().merge(((INetworkProvider) tileEntity).getNetwork()));
}
}
}
}
}
this.getNetwork().refresh();
}
}
use of micdoodle8.mods.galacticraft.planets.venus.tile.SolarModuleNetwork in project Galacticraft by micdoodle8.
the class VenusTickHandlerServer 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 == Phase.END) {
for (SolarModuleNetwork network : new ArrayList<>(solarModuleNetworks)) {
if (!network.getTransmitters().isEmpty()) {
// network.tickEnd();
} else {
solarModuleNetworks.remove(network);
}
}
int maxPasses = 10;
while (!solarTransmitterUpdates.isEmpty()) {
LinkedList<TileEntitySolarTransmitter> pass = new LinkedList<>();
pass.addAll(solarTransmitterUpdates);
solarTransmitterUpdates.clear();
for (TileEntitySolarTransmitter newTile : pass) {
if (!newTile.isInvalid()) {
newTile.refresh();
}
}
if (--maxPasses <= 0) {
break;
}
}
}
}
use of micdoodle8.mods.galacticraft.planets.venus.tile.SolarModuleNetwork in project Galacticraft by micdoodle8.
the class SolarModuleNetwork method split.
@Override
public void split(ITransmitter 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) {
ITransmitter[] nextToSplit = new ITransmitter[6];
boolean[] toDo = { true, true, true, true, true, true };
TileEntity tileEntity;
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 ITransmitter) {
nextToSplit[j] = (ITransmitter) tileEntity;
} else {
toDo[j] = false;
}
}
for (int i1 = 0; i1 < 6; i1++) {
if (toDo[i1]) {
ITransmitter connectedBlockA = nextToSplit[i1];
NetworkFinderSolar finder = new NetworkFinderSolar(world, new BlockVec3((TileEntity) connectedBlockA), new BlockVec3((TileEntity) splitPoint));
List<ITransmitter> 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++) {
ITransmitter connectedBlockB = nextToSplit[i2];
if (toDo[i2]) {
if (partNetwork.contains(connectedBlockB)) {
toDo[i2] = false;
}
}
}
// Now make the new network from partNetwork
SolarModuleNetwork newNetwork = new SolarModuleNetwork();
newNetwork.getTransmitters().addAll(partNetwork);
newNetwork.refreshWithChecks();
newNetwork.register();
}
}
this.destroy();
}
} else // Splitting a 1-block network leaves nothing
if (this.getTransmitters().size() == 0) {
this.destroy();
}
}
if (this.transmitters.isEmpty()) {
this.unregister();
}
}
Aggregations