use of de.slikey.effectlib.math.EquationTransform in project EffectLib by Slikey.
the class ModifiedEffect method onRun.
@Override
public void onRun() {
if (!initialized) {
initialized = true;
if (effect == null) {
effectManager.onError("ModifiedEffect missing inner effect configuration");
cancel();
return;
}
if (effectClass == null) {
effectClass = effect.getString("class");
}
if (effectClass == null) {
effectManager.onError("ModifiedEffect missing inner effect class property");
cancel();
return;
}
innerEffect = effectManager.getEffect(effectClass, effect, origin, target, null, targetPlayer);
if (innerEffect == null) {
cancel();
return;
}
innerEffect.materialData = materialData;
innerEffect.material = material;
for (Map.Entry<String, String> entry : parameters.entrySet()) {
String equation = entry.getValue();
String fieldName = entry.getKey();
// Allow underscore_style and dash_style parameters
if (fieldName.contains("-")) {
fieldName = fieldName.replace("-", "_");
}
if (fieldName.contains("_")) {
fieldName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, fieldName);
}
EquationTransform transform = EquationStore.getInstance().getTransform(equation, variables);
Exception ex = transform.getException();
if (ex != null) {
effectManager.onError("Error parsing equation: " + equation, ex);
continue;
}
try {
Field field = innerEffect.getClass().getField(fieldName);
parameterTransforms.put(field, transform);
} catch (Exception ex2) {
effectManager.onError("Error binding to field: " + fieldName + " of effect class " + effectClass, ex2);
continue;
}
}
innerEffect.prepare();
if (xEquation != null)
xTransform = EquationStore.getInstance().getTransform(xEquation, _variables);
if (yEquation != null)
yTransform = EquationStore.getInstance().getTransform(yEquation, _variables);
if (zEquation != null)
zTransform = EquationStore.getInstance().getTransform(zEquation, _variables);
}
if (innerEffect == null) {
cancel();
return;
}
if (origin != null && xTransform != null || yTransform != null || zTransform != null) {
Vector offset = new Vector(xTransform == null ? 0 : xTransform.get(step, maxIterations), yTransform == null ? 0 : yTransform.get(step, maxIterations), zTransform == null ? 0 : zTransform.get(step, maxIterations));
if (previousOffset != null) {
offset.subtract(previousOffset);
} else {
previousOffset = new Vector();
}
Location location = getLocation();
if (orient && orientPitch) {
offset = VectorUtils.rotateVector(offset, location);
} else if (orient) {
offset = VectorUtils.rotateVector(offset, location.getYaw(), 0);
}
origin.addOffset(offset);
previousOffset.add(offset);
}
for (Map.Entry<Field, EquationTransform> entry : parameterTransforms.entrySet()) {
double value = entry.getValue().get(step, maxIterations);
try {
Field field = entry.getKey();
if (field.getType().equals(Double.class) || field.getType().equals(Double.TYPE)) {
entry.getKey().set(innerEffect, value);
} else if (field.getType().equals(Integer.class) || field.getType().equals(Integer.TYPE)) {
entry.getKey().set(innerEffect, (int) value);
} else if (field.getType().equals(Float.class) || field.getType().equals(Float.TYPE)) {
entry.getKey().set(innerEffect, (float) value);
} else if (field.getType().equals(Short.class) || field.getType().equals(Short.TYPE)) {
entry.getKey().set(innerEffect, (short) value);
} else if (field.getType().equals(Byte.class) || field.getType().equals(Byte.TYPE)) {
entry.getKey().set(innerEffect, (byte) value);
} else {
effectManager.onError("Can't assign property " + entry.getKey().getName() + " of effect class " + effectClass + " of type " + field.getType().getName());
cancel();
return;
}
} catch (Exception ex) {
effectManager.onError("Error assigning to : " + entry.getKey().getName() + " of effect class " + effectClass, ex);
cancel();
return;
}
}
try {
innerEffect.onRun();
} catch (Exception ex) {
innerEffect.onDone();
effectManager.onError(ex);
}
step++;
}
use of de.slikey.effectlib.math.EquationTransform in project EffectLib by Slikey.
the class PlotEffect method onRun.
@Override
public void onRun() {
int base = persistent ? 0 : step;
for (int i = base; i <= step; i++) {
Location location = getLocation().clone();
double xOffset = step;
double yOffset = step;
double zOffset = 0;
if (xEquation != null && !xEquation.isEmpty()) {
EquationTransform xTransform = EquationStore.getInstance().getTransform(xEquation, variables);
xOffset = xTransform.get(i, maxIterations);
}
if (yEquation != null && !yEquation.isEmpty()) {
EquationTransform yTransform = EquationStore.getInstance().getTransform(yEquation, variables);
yOffset = yTransform.get(i, maxIterations);
}
if (zEquation != null && !zEquation.isEmpty()) {
EquationTransform zTransform = EquationStore.getInstance().getTransform(zEquation, variables);
zOffset = zTransform.get(i, maxIterations);
}
location.add(xOffset * xScale, yOffset * yScale, zOffset * zScale);
display(particle, location);
}
step++;
}
Aggregations