use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class CrystalMasterAxisTileEntity 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();
}
}
}
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class MasterAxisTileEntity method runCalc.
private void runCalc() {
double sumIRot = 0;
sumEnergy = 0;
for (IAxleHandler gear : rotaryMembers) {
sumIRot += gear.getPhysData()[1] * Math.pow(gear.getRotationRatio(), 2);
}
if (sumIRot == 0 || sumIRot != sumIRot) {
return;
}
sumEnergy = runLoss(rotaryMembers, 1.001D);
if (sumEnergy < 1 && sumEnergy > -1) {
sumEnergy = 0;
}
for (IAxleHandler gear : rotaryMembers) {
double newEnergy = 0;
// set w
gear.getMotionData()[0] = Math.signum(sumEnergy) * Math.signum(gear.getRotationRatio()) * Math.sqrt(Math.abs(sumEnergy) * 2D * Math.pow(gear.getRotationRatio(), 2) / sumIRot);
// set energy
newEnergy = Math.signum(gear.getMotionData()[0]) * Math.pow(gear.getMotionData()[0], 2) * gear.getPhysData()[1] / 2D;
gear.getMotionData()[1] = newEnergy;
// set power
gear.getMotionData()[2] = (newEnergy - gear.getMotionData()[3]) * 20;
// set lastE
gear.getMotionData()[3] = newEnergy;
gear.markChanged();
}
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class MasterAxisTileEntity 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();
}
}
}
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class ArcCosAxisTileEntity 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();
}
}
}
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class ArcCosAxisTileEntity method runCalc.
private void runCalc() {
double inBack = world.getTileEntity(pos.offset(facing.getOpposite())) != null && world.getTileEntity(pos.offset(facing.getOpposite())).hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing) ? world.getTileEntity(pos.offset(facing.getOpposite())).getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing).getMotionData()[0] : 0;
double baseSpeed = inBack < -1 || inBack > 1 ? 0 : Math.acos(inBack);
double sumIRot = 0;
sumEnergy = 0;
double cost = 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]));
}
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();
}
Aggregations