Search in sources :

Example 1 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class FluxReaderAxisTileEntity method runAngleCalc.

private void runAngleCalc() {
    boolean syncSpin = false;
    boolean work = false;
    for (IAxleHandler axle : rotaryMembers) {
        if (axle.shouldManageAngle()) {
            syncSpin = Math.abs(axle.getMotionData()[0] - axle.getClientW()) >= CLIENT_SPEED_MARGIN * axle.getRotationRatio();
            work = true;
            break;
        }
    }
    if (!work) {
        return;
    }
    for (IAxleHandler axle : rotaryMembers) {
        if (axle.shouldManageAngle()) {
            float axleSpeed = ((float) axle.getMotionData()[0]);
            axle.setAngle(axle.getAngle() + (axleSpeed * 9F / (float) Math.PI));
            if (syncSpin) {
                axle.syncAngle();
            }
        }
    }
}
Also used : IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)

Example 2 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class FluxReaderAxisTileEntity method runCalc.

private void runCalc() {
    FieldWorldSavedData data = FieldWorldSavedData.get(world);
    double baseSpeed = data.fieldNodes.containsKey(MiscOp.getLongFromChunkPos(new ChunkPos(pos))) ? EnergyConverters.SPEED_PER_FLUX * data.fieldNodes.get(MiscOp.getLongFromChunkPos(new ChunkPos(pos)))[0][MiscOp.getChunkRelativeCoord(pos.getX()) / 2][MiscOp.getChunkRelativeCoord(pos.getZ()) / 2] : 0;
    double sumIRot = 0;
    sumEnergy = 0;
    for (IAxleHandler gear : rotaryMembers) {
        sumIRot += gear.getPhysData()[1] * Math.pow(gear.getRotationRatio(), 2);
        sumEnergy += Math.signum(gear.getRotationRatio()) * gear.getMotionData()[1] * Math.pow(1.001D, -Math.abs(gear.getMotionData()[0]));
    }
    double cost = sumIRot * Math.pow(baseSpeed, 2) / 2D;
    TileEntity backTE = world.getTileEntity(pos.offset(facing.getOpposite()));
    double availableEnergy = Math.abs(sumEnergy) + Math.abs(backTE != null && backTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing) ? backTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing).getMotionData()[1] : 0);
    if (availableEnergy - cost < 0) {
        baseSpeed = 0;
        cost = 0;
    }
    availableEnergy -= cost;
    for (IAxleHandler gear : rotaryMembers) {
        double newEnergy = 0;
        // set w
        gear.getMotionData()[0] = gear.getRotationRatio() * baseSpeed;
        // set energy
        newEnergy = Math.signum(gear.getMotionData()[0]) * Math.pow(gear.getMotionData()[0], 2) * gear.getPhysData()[1] / 2D;
        gear.getMotionData()[1] = newEnergy;
        sumEnergy += newEnergy;
        // set power
        gear.getMotionData()[2] = (newEnergy - gear.getMotionData()[3]) * 20;
        // set lastE
        gear.getMotionData()[3] = newEnergy;
        gear.markChanged();
    }
    if (backTE != null && backTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing)) {
        backTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing).getMotionData()[1] = availableEnergy * MiscOp.posOrNeg(backTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing).getMotionData()[1], 1);
    }
    runAngleCalc();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler) FieldWorldSavedData(com.Da_Technomancer.crossroads.API.technomancy.FieldWorldSavedData) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 3 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class GreaterThanAxisTileEntity method runCalc.

private void runCalc() {
    TileEntity backTE = world.getTileEntity(pos.offset(facing.getOpposite()));
    double inBack = backTE != null && backTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing) ? backTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing).getMotionData()[0] : 0;
    TileEntity topTE = world.getTileEntity(pos.offset(EnumFacing.UP));
    double inTop = topTE != null && topTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN) ? topTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN).getMotionData()[0] : 0;
    if (facing.getAxisDirection() == AxisDirection.POSITIVE && world.getBlockState(pos.offset(facing.getOpposite())).getBlock() == ModBlocks.axle) {
        inBack *= -1D;
    }
    double baseSpeed = (inBack > inTop) ? inBack : 0;
    double sumIRot = 0;
    sumEnergy = 0;
    for (IAxleHandler gear : rotaryMembers) {
        sumIRot += gear.getPhysData()[1] * Math.pow(gear.getRotationRatio(), 2);
        sumEnergy += Math.signum(gear.getRotationRatio()) * gear.getMotionData()[1] * Math.pow(1.001D, -Math.abs(gear.getMotionData()[0]));
    }
    double cost = sumIRot * Math.pow(baseSpeed, 2) / 2D;
    TileEntity downTE = world.getTileEntity(pos.offset(EnumFacing.DOWN));
    double availableEnergy = Math.abs(sumEnergy) + Math.abs(downTE != null && downTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP) ? downTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP).getMotionData()[1] : 0);
    if (availableEnergy - cost < 0) {
        baseSpeed = 0;
        cost = 0;
    }
    availableEnergy -= cost;
    for (IAxleHandler gear : rotaryMembers) {
        double newEnergy = 0;
        // set w
        gear.getMotionData()[0] = gear.getRotationRatio() * baseSpeed;
        // set energy
        newEnergy = Math.signum(gear.getMotionData()[0]) * Math.pow(gear.getMotionData()[0], 2) * gear.getPhysData()[1] / 2D;
        gear.getMotionData()[1] = newEnergy;
        sumEnergy += newEnergy;
        // set power
        gear.getMotionData()[2] = (newEnergy - gear.getMotionData()[3]) * 20;
        // set lastE
        gear.getMotionData()[3] = newEnergy;
        gear.markChanged();
    }
    if (downTE != null && downTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP)) {
        downTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP).getMotionData()[1] = availableEnergy * MiscOp.posOrNeg(downTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP).getMotionData()[1], 1);
    }
    runAngleCalc();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)

Example 4 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class LessThanAxisTileEntity method runAngleCalc.

private void runAngleCalc() {
    boolean syncSpin = false;
    boolean work = false;
    for (IAxleHandler axle : rotaryMembers) {
        if (axle.shouldManageAngle()) {
            syncSpin = Math.abs(axle.getMotionData()[0] - axle.getClientW()) >= CLIENT_SPEED_MARGIN * axle.getRotationRatio();
            work = true;
            break;
        }
    }
    if (!work) {
        return;
    }
    for (IAxleHandler axle : rotaryMembers) {
        if (axle.shouldManageAngle()) {
            float axleSpeed = ((float) axle.getMotionData()[0]);
            axle.setAngle(axle.getAngle() + (axleSpeed * 9F / (float) Math.PI));
            if (syncSpin) {
                axle.syncAngle();
            }
        }
    }
}
Also used : IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)

Example 5 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class MultiplicationAxisTileEntity method runAngleCalc.

private void runAngleCalc() {
    boolean syncSpin = false;
    boolean work = false;
    for (IAxleHandler axle : rotaryMembers) {
        if (axle.shouldManageAngle()) {
            syncSpin = Math.abs(axle.getMotionData()[0] - axle.getClientW()) >= CLIENT_SPEED_MARGIN * axle.getRotationRatio();
            work = true;
            break;
        }
    }
    if (!work) {
        return;
    }
    for (IAxleHandler axle : rotaryMembers) {
        if (axle.shouldManageAngle()) {
            float axleSpeed = ((float) axle.getMotionData()[0]);
            axle.setAngle(axle.getAngle() + (axleSpeed * 9F / (float) Math.PI));
            if (syncSpin) {
                axle.syncAngle();
            }
        }
    }
}
Also used : IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)

Aggregations

IAxleHandler (com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)37 TileEntity (net.minecraft.tileentity.TileEntity)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 EnumFacing (net.minecraft.util.EnumFacing)3 SendSpinToClient (com.Da_Technomancer.crossroads.API.packets.SendSpinToClient)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)2 BeamRenderTEBase (com.Da_Technomancer.crossroads.API.magic.BeamRenderTEBase)1 MagicUnit (com.Da_Technomancer.crossroads.API.magic.MagicUnit)1 SendFieldsToClient (com.Da_Technomancer.crossroads.API.packets.SendFieldsToClient)1 FieldWorldSavedData (com.Da_Technomancer.crossroads.API.technomancy.FieldWorldSavedData)1 RatiatorTileEntity (com.Da_Technomancer.crossroads.tileentities.RatiatorTileEntity)1 CrystalMasterAxisTileEntity (com.Da_Technomancer.crossroads.tileentities.magic.CrystalMasterAxisTileEntity)1 Color (java.awt.Color)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 FoodStats (net.minecraft.util.FoodStats)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1