Search in sources :

Example 6 with Connection

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

the class ItemSkyhook method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    TileEntity connector = null;
    double lastDist = 0;
    Connection line = null;
    double py = player.posY + player.getEyeHeight();
    for (int xx = -2; xx <= 2; xx++) for (int zz = -2; zz <= 2; zz++) for (int yy = 0; yy <= 3; yy++) {
        TileEntity tile = world.getTileEntity(new BlockPos(player.posX + xx, py + yy, player.posZ + zz));
        if (tile != null) {
            Connection con = SkylineHelper.getTargetConnection(world, tile.getPos(), player, null);
            if (con != null) {
                double d = tile.getDistanceSq(player.posX, py, player.posZ);
                if (connector == null || d < lastDist) {
                    connector = tile;
                    lastDist = d;
                    line = con;
                }
            }
        }
    }
    if (line != null && connector != null) {
        SkylineHelper.spawnHook(player, connector, line);
        player.setActiveHand(hand);
        return new ActionResult(EnumActionResult.SUCCESS, stack);
    }
    return new ActionResult(EnumActionResult.PASS, stack);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with Connection

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

the class SkylineHelper method getTargetConnection.

public static Connection getTargetConnection(World world, BlockPos pos, EntityLivingBase living, Connection invalidCon) {
    if (!(world.getTileEntity(pos) instanceof IImmersiveConnectable))
        return null;
    Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, pos);
    if (outputs != null && outputs.size() > 0) {
        Vec3d vec = living.getLookVec();
        vec = vec.normalize();
        Connection line = null;
        for (Connection c : outputs) if (c != null && !c.hasSameConnectors(invalidCon)) {
            if (line == null)
                line = c;
            else {
                Vec3d lineVec = new Vec3d(line.end.getX() - line.start.getX(), line.end.getY() - line.start.getY(), line.end.getZ() - line.start.getZ()).normalize();
                Vec3d conVec = new Vec3d(c.end.getX() - c.start.getX(), c.end.getY() - c.start.getY(), c.end.getZ() - c.start.getZ()).normalize();
                if (conVec.distanceTo(vec) < lineVec.distanceTo(vec))
                    line = c;
            }
        }
        return line;
    }
    return null;
}
Also used : Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) Vec3d(net.minecraft.util.math.Vec3d)

Example 8 with Connection

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

the class TileEntityImmersiveConnectable method writeConnsToNBT.

private void writeConnsToNBT(NBTTagCompound nbt) {
    if (worldObj != null && !worldObj.isRemote && nbt != null) {
        NBTTagList connectionList = new NBTTagList();
        Set<Connection> conL = ImmersiveNetHandler.INSTANCE.getConnections(worldObj, Utils.toCC(this));
        if (conL != null)
            for (Connection con : conL) connectionList.appendTag(con.writeToNBT());
        nbt.setTag("connectionList", connectionList);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)

Example 9 with Connection

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

the class TileEntityImmersiveConnectable method loadConnsFromNBT.

private void loadConnsFromNBT(NBTTagCompound nbt) {
    if (worldObj != null && worldObj.isRemote && !Minecraft.getMinecraft().isSingleplayer() && nbt != null) {
        NBTTagList connectionList = nbt.getTagList("connectionList", 10);
        ImmersiveNetHandler.INSTANCE.clearConnectionsOriginatingFrom(Utils.toCC(this), worldObj);
        for (int i = 0; i < connectionList.tagCount(); i++) {
            NBTTagCompound conTag = connectionList.getCompoundTagAt(i);
            Connection con = Connection.readFromNBT(conTag);
            if (con != null) {
                ImmersiveNetHandler.INSTANCE.addConnection(worldObj, Utils.toCC(this), con);
            } else
                IELogger.error("CLIENT read connection as null");
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)

Example 10 with Connection

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

the class TileEntityConnectorLV method transferEnergy.

public int transferEnergy(int energy, boolean simulate, final int energyType) {
    int received = 0;
    if (!worldObj.isRemote) {
        Set<AbstractConnection> outputs = ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(Utils.toCC(this), worldObj);
        int powerLeft = Math.min(Math.min(getMaxOutput(), getMaxInput()), energy);
        final int powerForSort = powerLeft;
        if (outputs.size() < 1)
            return 0;
        int sum = 0;
        HashMap<AbstractConnection, Integer> powerSorting = new HashMap<AbstractConnection, Integer>();
        for (AbstractConnection con : outputs) {
            IImmersiveConnectable end = ApiUtils.toIIC(con.end, worldObj);
            if (con.cableType != null && end != null) {
                int atmOut = Math.min(powerForSort, con.cableType.getTransferRate());
                int tempR = end.outputEnergy(atmOut, true, energyType);
                if (tempR > 0) {
                    powerSorting.put(con, tempR);
                    sum += tempR;
                }
            }
        }
        if (sum > 0)
            for (AbstractConnection con : powerSorting.keySet()) {
                IImmersiveConnectable end = ApiUtils.toIIC(con.end, worldObj);
                if (con.cableType != null && end != null) {
                    float prio = powerSorting.get(con) / (float) sum;
                    int output = (int) (powerForSort * prio);
                    int tempR = end.outputEnergy(Math.min(output, con.cableType.getTransferRate()), true, energyType);
                    int r = tempR;
                    int maxInput = getMaxInput();
                    tempR -= (int) Math.max(0, Math.floor(tempR * con.getPreciseLossRate(tempR, maxInput)));
                    end.outputEnergy(tempR, simulate, energyType);
                    HashSet<IImmersiveConnectable> passedConnectors = new HashSet<IImmersiveConnectable>();
                    float intermediaryLoss = 0;
                    for (Connection sub : con.subConnections) {
                        float length = sub.length / (float) sub.cableType.getMaxLength();
                        float baseLoss = (float) sub.cableType.getLossRatio();
                        float mod = (((maxInput - tempR) / (float) maxInput) / .25f) * .1f;
                        intermediaryLoss = MathHelper.clamp_float(intermediaryLoss + length * (baseLoss + baseLoss * mod), 0, 1);
                        int transferredPerCon = ImmersiveNetHandler.INSTANCE.getTransferedRates(worldObj.provider.getDimension()).containsKey(sub) ? ImmersiveNetHandler.INSTANCE.getTransferedRates(worldObj.provider.getDimension()).get(sub) : 0;
                        transferredPerCon += r;
                        if (!simulate) {
                            ImmersiveNetHandler.INSTANCE.getTransferedRates(worldObj.provider.getDimension()).put(sub, transferredPerCon);
                            IImmersiveConnectable subStart = ApiUtils.toIIC(sub.start, worldObj);
                            IImmersiveConnectable subEnd = ApiUtils.toIIC(sub.end, worldObj);
                            if (subStart != null && passedConnectors.add(subStart))
                                subStart.onEnergyPassthrough((int) (r - r * intermediaryLoss));
                            if (subEnd != null && passedConnectors.add(subEnd))
                                subEnd.onEnergyPassthrough((int) (r - r * intermediaryLoss));
                        }
                    }
                    received += r;
                    powerLeft -= r;
                    if (powerLeft <= 0)
                        break;
                }
            }
    }
    return received;
}
Also used : HashMap(java.util.HashMap) AbstractConnection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) AbstractConnection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) 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