Skip to content

Commit

Permalink
[TASK] Add float support to calcyawto
Browse files Browse the repository at this point in the history
  • Loading branch information
spthiel committed Apr 9, 2023
1 parent 7f127a9 commit c1df869
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ group=me.spthiel.klacaiba
archivesBaseName=Klacaiba

#Version of your project
version=3.0.0-beta.9
version=3.0.0-beta.10

################################################################################
# Module settings
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/me/spthiel/klacaiba/base/FloatReturnValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

public class FloatReturnValue implements IReturnValue {

private final float value;
private float value;

public FloatReturnValue(float value) {
this.value = value;
}

public void setValue(float value) {
this.value = value;
}

@Override
public boolean isVoid() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Arrays;

import me.spthiel.klacaiba.base.BaseScriptAction;
import me.spthiel.klacaiba.base.FloatReturnValue;

public class CalcYawTo extends BaseScriptAction {

Expand All @@ -18,7 +19,7 @@ public CalcYawTo() {
}

public IReturnValue run(IScriptActionProvider provider, IMacro macro, IMacroAction instance, String rawParams, String[] params) {
ReturnValue retVal = new ReturnValue(0);
FloatReturnValue retVal = new FloatReturnValue(0);
if (params.length > 1 && this.mc != null && this.mc.player != null) {
if (params.length > 2 && !Variable.isValidVariableName(provider.expand(macro, params[2], false))) {
float xPos = getValue(provider, macro, params[0]);
Expand All @@ -37,25 +38,21 @@ public IReturnValue run(IScriptActionProvider provider, IMacro macro, IMacroActi
String varName;
if (params.length > 3) {

int yaw;
yaw = (int) (Math.atan2(deltaZ, deltaX) * 180.0D / Math.PI - 90.0D);
double yaw;
yaw = (Math.atan2(deltaZ, deltaX) * 180.0D / Math.PI - 90.0D);
while (yaw < 0) {

yaw += 360;
}

varName = provider.expand(macro, params[3], false);
provider.setVariable(macro, varName, yaw);
setVariableFloat(provider, macro, params[3], yaw);
}

if (params.length > 4) {
varName = provider.expand(macro, params[4], false);
provider.setVariable(macro, varName, MathHelper.floor(distance));
setVariableFloat(provider, macro, params[4], distance);
}

if (params.length > 5) {
varName = provider.expand(macro, params[5], false);
provider.setVariable(macro, varName, MathHelper.floor(360-pitchFromPlayer));
setVariableFloat(provider, macro, params[5], 360-pitchFromPlayer);
}
} else {
float xPos = (float)ScriptCore.tryParseInt(provider.expand(macro, params[0], false), 0) + 0.5F;
Expand All @@ -70,7 +67,7 @@ public IReturnValue run(IScriptActionProvider provider, IMacro macro, IMacroActi
yaw += 360;
}

retVal.setInt(yaw);
retVal.setValue(yaw);
String varName;
if (params.length > 2) {
varName = provider.expand(macro, params[2], false);
Expand All @@ -87,6 +84,15 @@ public IReturnValue run(IScriptActionProvider provider, IMacro macro, IMacroActi
return retVal;
}

private void setVariableFloat(IScriptActionProvider provider, IMacro macro, String variable, double value) {
String varname = provider.expand(macro, variable, false);
if (Variable.couldBeInt(variable)) {
provider.setVariable(macro, variable, (int)value);
} else {
provider.setVariable(macro, variable, Float.toString((float)value));
}
}

private float getValue(IScriptActionProvider provider, IMacro macro, String param) {
String expanded = provider.expand(macro, param, false);
if(expanded.matches("-?\\d+")) {
Expand Down

0 comments on commit c1df869

Please sign in to comment.