Search in sources :

Example 6 with ITransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter 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 7 with ITransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter in project Galacticraft by micdoodle8.

the class SolarModuleNetwork method refresh.

@Override
public void refresh() {
    Iterator<ITransmitter> it = this.transmitters.iterator();
    while (it.hasNext()) {
        ITransmitter conductor = it.next();
        if (conductor == null) {
            it.remove();
            continue;
        }
        TileEntity tile = (TileEntity) conductor;
        World world = tile.getWorld();
        // Remove any transmitters in unloaded chunks
        if (tile.isInvalid() || world == null) {
            it.remove();
            continue;
        }
        if (conductor.getNetwork() != this) {
            conductor.setNetwork(this);
            conductor.onNetworkChanged();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter) World(net.minecraft.world.World)

Example 8 with ITransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter 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)

Example 9 with ITransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter in project Galacticraft by micdoodle8.

the class BlockTransmitter method addCollisionBoxesToList.

@Override
public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) {
    Vector3 minVector = this.getMinVector(state);
    Vector3 maxVector = this.getMaxVector(state);
    this.setBlockBounds((float) minVector.x, (float) minVector.y, (float) minVector.z, (float) maxVector.x, (float) maxVector.y, (float) maxVector.z);
    super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (tileEntity instanceof ITransmitter) {
        TileEntity[] connectable;
        switch(this.getNetworkType(state)) {
            case FLUID:
                connectable = OxygenUtil.getAdjacentFluidConnections(tileEntity);
                break;
            case POWER:
                connectable = EnergyUtil.getAdjacentPowerConnections(tileEntity);
                break;
            default:
                connectable = new TileEntity[6];
        }
        if (connectable[4] != null) {
            this.setBlockBounds(0, (float) minVector.y, (float) minVector.z, (float) maxVector.x, (float) maxVector.y, (float) maxVector.z);
            super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
        }
        if (connectable[5] != null) {
            this.setBlockBounds((float) minVector.x, (float) minVector.y, (float) minVector.z, 1, (float) maxVector.y, (float) maxVector.z);
            super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
        }
        if (connectable[0] != null) {
            this.setBlockBounds((float) minVector.x, 0, (float) minVector.z, (float) maxVector.x, (float) maxVector.y, (float) maxVector.z);
            super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
        }
        if (connectable[1] != null) {
            this.setBlockBounds((float) minVector.x, (float) minVector.y, (float) minVector.z, (float) maxVector.x, 1, (float) maxVector.z);
            super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
        }
        if (connectable[2] != null) {
            this.setBlockBounds((float) minVector.x, (float) minVector.y, 0, (float) maxVector.x, (float) maxVector.y, (float) maxVector.z);
            super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
        }
        if (connectable[3] != null) {
            this.setBlockBounds((float) minVector.x, (float) minVector.y, (float) minVector.z, (float) maxVector.x, (float) maxVector.y, 1);
            super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
        }
    }
    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3)

Example 10 with ITransmitter

use of micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter in project Galacticraft by micdoodle8.

the class BlockTransmitter method setBlockBoundsBasedOnState.

/**
 * Returns the bounding box of the wired rectangular prism to render.
 */
@Override
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    IBlockState bs = worldIn.getBlockState(pos);
    if (tileEntity instanceof ITransmitter && bs.getBlock() instanceof BlockTransmitter) {
        Vector3 minVector = this.getMinVector(bs);
        Vector3 maxVector = this.getMaxVector(bs);
        TileEntity[] connectable = new TileEntity[6];
        switch(this.getNetworkType(bs)) {
            case FLUID:
                connectable = OxygenUtil.getAdjacentFluidConnections(tileEntity);
                break;
            case POWER:
                connectable = EnergyUtil.getAdjacentPowerConnections(tileEntity);
                break;
            default:
                break;
        }
        float minX = (float) minVector.x;
        float minY = (float) minVector.y;
        float minZ = (float) minVector.z;
        float maxX = (float) maxVector.x;
        float maxY = (float) maxVector.y;
        float maxZ = (float) maxVector.z;
        if (connectable[0] != null) {
            minY = 0.0F;
        }
        if (connectable[1] != null) {
            maxY = 1.0F;
        }
        if (connectable[2] != null) {
            minZ = 0.0F;
        }
        if (connectable[3] != null) {
            maxZ = 1.0F;
        }
        if (connectable[4] != null) {
            minX = 0.0F;
        }
        if (connectable[5] != null) {
            maxX = 1.0F;
        }
        this.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ITransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3)

Aggregations

ITransmitter (micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter)13 TileEntity (net.minecraft.tileentity.TileEntity)13 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)5 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)3 EnumFacing (net.minecraft.util.EnumFacing)3 World (net.minecraft.world.World)3 IGridNetwork (micdoodle8.mods.galacticraft.api.transmission.grid.IGridNetwork)2 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)2 IBlockState (net.minecraft.block.state.IBlockState)2 IBufferTransmitter (micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)1 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)1 WorldProviderVenus (micdoodle8.mods.galacticraft.planets.venus.dimension.WorldProviderVenus)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3i (net.minecraft.util.math.Vec3i)1