Search in sources :

Example 11 with Connection

use of blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection in project ImmersiveEngineering by BluSunrize.

the class TileEntityBreakerSwitch method calculateLeftConn.

protected void calculateLeftConn(Matrix4 transform) {
    Vec3d leftVec = transform.apply(new Vec3d(-1, .5, .5)).subtract(0, .5, .5);
    EnumFacing dir = EnumFacing.getFacingFromVector((float) leftVec.xCoord, (float) leftVec.yCoord, (float) leftVec.zCoord);
    int maxDiff = Integer.MIN_VALUE;
    Set<Connection> conns = ImmersiveNetHandler.INSTANCE.getConnections(worldObj, pos);
    if (conns != null)
        for (Connection c : conns) {
            Vec3i diff = pos.equals(c.start) ? c.end.subtract(pos) : c.start.subtract(pos);
            int val = 0;
            switch(dir.getAxis()) {
                case X:
                    val = diff.getX();
                    break;
                case Y:
                    val = diff.getY();
                    break;
                case Z:
                    val = diff.getZ();
            }
            val *= dir.getAxisDirection().getOffset();
            if (val > maxDiff) {
                maxDiff = val;
                endOfLeftConnection = pos == c.end ? c.start : c.end;
            }
        }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) EnumFacing(net.minecraft.util.EnumFacing) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) Vec3d(net.minecraft.util.math.Vec3d)

Example 12 with Connection

use of blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection in project ImmersiveEngineering by BluSunrize.

the class TileEntityBreakerSwitch method onConnectionChange.

protected void onConnectionChange() {
    if (worldObj != null && worldObj.isRemote) {
        endOfLeftConnection = null;
        ImmersiveEngineering.proxy.clearConnectionModelCache();
        // reset cached connection vertices
        Set<Connection> conns = ImmersiveNetHandler.INSTANCE.getConnections(worldObj, pos);
        if (conns != null)
            for (Connection c : conns) {
                c.catenaryVertices = null;
                worldObj.markBlockRangeForRenderUpdate(c.end, c.end);
                Set<Connection> connsThere = ImmersiveNetHandler.INSTANCE.getConnections(worldObj, c.end);
                if (connsThere != null)
                    for (Connection c2 : connsThere) if (c2.end.equals(pos))
                        c2.catenaryVertices = null;
            }
    }
    if (worldObj != null)
        markContainingBlockForUpdate(null);
}
Also used : Set(java.util.Set) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)

Example 13 with Connection

use of blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection in project ImmersiveEngineering by BluSunrize.

the class TileEntityEnergyMeter method updateComparatorValues.

private void updateComparatorValues() {
    int oldVal = compVal;
    int maxTrans = 0;
    Set<Connection> conns = ImmersiveNetHandler.INSTANCE.getConnections(worldObj, dummy ? pos.up() : pos);
    if (conns == null) {
        compVal = 0;
        return;
    }
    for (Connection c : conns) maxTrans += c.cableType.getTransferRate();
    maxTrans /= 2;
    double val = getAveragePower() / (double) maxTrans;
    compVal = (int) Math.ceil(15 * val);
    if (oldVal != compVal)
        worldObj.updateComparatorOutputLevel(pos, getBlockType());
}
Also used : Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)

Example 14 with Connection

use of blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection in project ImmersiveEngineering by BluSunrize.

the class TileEntityConnectorLV method update.

@Override
public void update() {
    if (!worldObj.isRemote) {
        //				}
        if (energyStorage.getEnergyStored() > 0) {
            int temp = this.transferEnergy(energyStorage.getEnergyStored(), true, 0);
            if (temp > 0) {
                energyStorage.modifyEnergyStored(-this.transferEnergy(temp, false, 0));
                markDirty();
            }
        }
        currentTickAccepted = 0;
    } else if (firstTick) {
        Set<Connection> conns = ImmersiveNetHandler.INSTANCE.getConnections(worldObj, pos);
        if (conns != null)
            for (Connection conn : conns) if (pos.compareTo(conn.end) < 0 && worldObj.isBlockLoaded(conn.end))
                this.markContainingBlockForUpdate(null);
        firstTick = false;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) AbstractConnection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection)

Example 15 with Connection

use of blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection in project ImmersiveEngineering by BluSunrize.

the class TileEntityImmersiveConnectable method genConnBlockstate.

public Set<Connection> genConnBlockstate() {
    Set<Connection> conns = ImmersiveNetHandler.INSTANCE.getConnections(worldObj, pos);
    if (conns == null)
        return ImmutableSet.of();
    Set<Connection> ret = new HashSet<Connection>() {

        @Override
        public boolean equals(Object o) {
            if (o == this)
                return true;
            if (!(o instanceof HashSet))
                return false;
            HashSet<Connection> other = (HashSet<Connection>) o;
            if (other.size() != this.size())
                return false;
            for (Connection c : this) if (!other.contains(c))
                return false;
            return true;
        }
    };
    for (Connection c : conns) {
        IImmersiveConnectable end = ApiUtils.toIIC(c.end, worldObj, false);
        if (end == null)
            continue;
        // generate subvertices
        c.getSubVertices(worldObj);
        ret.add(c);
    }
    return ret;
}
Also used : Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) HashSet(java.util.HashSet)

Aggregations

Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)20 BlockPos (net.minecraft.util.math.BlockPos)6 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)5 TileEntity (net.minecraft.tileentity.TileEntity)5 Vec3d (net.minecraft.util.math.Vec3d)5 HashSet (java.util.HashSet)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 IBlockState (net.minecraft.block.state.IBlockState)3 DimensionChunkCoords (blusunrize.immersiveengineering.api.DimensionChunkCoords)2 IICProxy (blusunrize.immersiveengineering.api.energy.wires.IICProxy)2 AbstractConnection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection)2 MineralWorldInfo (blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo)2 Set (java.util.Set)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 DimensionBlockPos (blusunrize.immersiveengineering.api.DimensionBlockPos)1 TargetingInfo (blusunrize.immersiveengineering.api.TargetingInfo)1