Search in sources :

Example 1 with SolarModuleNetwork

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();
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) EnumFacing(net.minecraft.util.EnumFacing) ITransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter) INetworkProvider(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider) TileEntity(net.minecraft.tileentity.TileEntity) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) WorldProviderVenus(micdoodle8.mods.galacticraft.planets.venus.dimension.WorldProviderVenus)

Example 2 with SolarModuleNetwork

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();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IGridNetwork(micdoodle8.mods.galacticraft.api.transmission.grid.IGridNetwork) EnumFacing(net.minecraft.util.EnumFacing) ITransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter) INetworkProvider(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 3 with SolarModuleNetwork

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;
            }
        }
    }
}
Also used : TileEntitySolarTransmitter(micdoodle8.mods.galacticraft.planets.venus.tile.TileEntitySolarTransmitter) SolarModuleNetwork(micdoodle8.mods.galacticraft.planets.venus.tile.SolarModuleNetwork) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with SolarModuleNetwork

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();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter) World(net.minecraft.world.World) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Aggregations

ITransmitter (micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter)3 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 TileEntity (net.minecraft.tileentity.TileEntity)3 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)2 EnumFacing (net.minecraft.util.EnumFacing)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 IGridNetwork (micdoodle8.mods.galacticraft.api.transmission.grid.IGridNetwork)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)1 WorldProviderVenus (micdoodle8.mods.galacticraft.planets.venus.dimension.WorldProviderVenus)1 SolarModuleNetwork (micdoodle8.mods.galacticraft.planets.venus.tile.SolarModuleNetwork)1 TileEntitySolarTransmitter (micdoodle8.mods.galacticraft.planets.venus.tile.TileEntitySolarTransmitter)1 IBlockState (net.minecraft.block.state.IBlockState)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 Vec3i (net.minecraft.util.math.Vec3i)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1