use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class MultiplicationAxisTileEntity method runCalc.
private void runCalc() {
TileEntity backTE = world.getTileEntity(pos.offset(facing.getOpposite()));
double inOne = 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 inTwo = 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) {
inOne *= -1D;
}
double baseSpeed = inTwo == 0 ? 0 : world.getBlockState(pos).getValue(Properties.REDSTONE_BOOL) ? -inOne / inTwo : -inOne * inTwo;
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);
}
if (facing.getAxisDirection() == AxisDirection.NEGATIVE) {
inOne *= -1D;
}
if (Math.abs(inOne - lastInOne) >= CLIENT_SPEED_MARGIN) {
lastInOne = (float) inOne;
ModPackets.network.sendToAllAround(new SendSpinToClient(1, lastInOne, 0, pos), new TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 512));
}
if (Math.abs(inTwo - lastInTwo) >= CLIENT_SPEED_MARGIN) {
lastInTwo = (float) inTwo;
ModPackets.network.sendToAllAround(new SendSpinToClient(1, lastInTwo, 0, pos), new TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 512));
}
runAngleCalc();
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class AdditionAxisTileEntity 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 AdditionAxisTileEntity method runCalc.
private void runCalc() {
TileEntity posTE = world.getTileEntity(pos.offset(EnumFacing.getFacingFromAxis(AxisDirection.POSITIVE, axis)));
double inPos = posTE != null && posTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.getFacingFromAxis(AxisDirection.NEGATIVE, axis)) ? posTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.getFacingFromAxis(AxisDirection.NEGATIVE, axis)).getMotionData()[0] : 0;
TileEntity negTE = world.getTileEntity(pos.offset(EnumFacing.getFacingFromAxis(AxisDirection.NEGATIVE, axis)));
double inNeg = negTE != null && negTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.getFacingFromAxis(AxisDirection.POSITIVE, axis)) ? negTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.getFacingFromAxis(AxisDirection.POSITIVE, axis)).getMotionData()[0] : 0;
if (world.getBlockState(pos.offset(EnumFacing.getFacingFromAxis(AxisDirection.NEGATIVE, axis))).getBlock() == ModBlocks.axle) {
inNeg *= -1D;
}
double baseSpeed = inPos + inNeg;
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];
cost += Math.abs(gear.getMotionData()[1] * (1D - 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);
}
inPos *= -1D;
if (Math.abs(lastInPos - inPos) >= CLIENT_SPEED_MARGIN) {
lastInPos = (float) inPos;
ModPackets.network.sendToAllAround(new SendSpinToClient(0, lastInPos, 0, pos), new TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 512));
}
if (Math.abs(inNeg - lastInNeg) >= CLIENT_SPEED_MARGIN) {
lastInNeg = (float) inNeg;
ModPackets.network.sendToAllAround(new SendSpinToClient(1, lastInNeg, 0, pos), new TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 512));
}
runAngleCalc();
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class ArcSinAxisTileEntity 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 CosAxisTileEntity 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();
}
}
}
}
Aggregations