Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
BarstowBadlands authored Aug 13, 2017
1 parent cc75b6c commit cd98847
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/TheRPGAdventurer/ROTD/util/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.TheRPGAdventurer.ROTD.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.TheRPGAdventurer.ROTD.RealmOfTheDragons;

public class Utils {

private static Logger logger;

public static Logger getLogger() {
if(logger == null) {
logger = LogManager.getFormatterLogger(RealmOfTheDragons.MODID);
}
return logger;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
** 2016 March 05
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
*/
package com.TheRPGAdventurer.ROTD.util.math;

/**
* Interpolation utility class.
*
* @author Nico Bergemann <barracuda415 at yahoo.de>
*/
public class Interpolation {

private static final float[][] CR = {
{-0.5f, 1.5f, -1.5f, 0.5f},
{ 1.0f, -2.5f, 2.0f, -0.5f},
{-0.5f, 0.0f, 0.5f, 0.0f},
{ 0.0f, 1.0f, 0.0f, 0.0f}
};

public static float linear(float a, float b, float x) {
if (x <= 0) {
return a;
}
if (x >= 1) {
return b;
}
return a * (1 - x) + b * x;
}

public static float smoothStep(float a, float b, float x) {
if (x <= 0) {
return a;
}
if (x >= 1) {
return b;
}
x = x * x * (3 - 2 * x);
return a * (1 - x) + b * x;
}

// http://www.java-gaming.org/index.php?topic=24122.0
public static void catmullRomSpline(float x, float[] result, float[]... knots) {
int nknots = knots.length;
int nspans = nknots - 3;
int knot = 0;
if (nspans < 1) {
throw new IllegalArgumentException("Spline has too few knots");
}
x = MathX.clamp(x, 0, 0.9999f) * nspans;

int span = (int) x;
if (span >= nknots - 3) {
span = nknots - 3;
}

x -= span;
knot += span;

int dimension = result.length;
for (int i = 0; i < dimension; i++) {
float knot0 = knots[knot][i];
float knot1 = knots[knot + 1][i];
float knot2 = knots[knot + 2][i];
float knot3 = knots[knot + 3][i];

float c3 = CR[0][0] * knot0 + CR[0][1] * knot1 + CR[0][2] * knot2 + CR[0][3] * knot3;
float c2 = CR[1][0] * knot0 + CR[1][1] * knot1 + CR[1][2] * knot2 + CR[1][3] * knot3;
float c1 = CR[2][0] * knot0 + CR[2][1] * knot1 + CR[2][2] * knot2 + CR[2][3] * knot3;
float c0 = CR[3][0] * knot0 + CR[3][1] * knot1 + CR[3][2] * knot2 + CR[3][3] * knot3;

result[i] = ((c3 * x + c2) * x + c1) * x + c0;
}
}

private Interpolation() {
}
}
129 changes: 129 additions & 0 deletions src/main/java/com/TheRPGAdventurer/ROTD/util/math/MathX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
** 2012 Januar 8
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
*/
package com.TheRPGAdventurer.ROTD.util.math;

/**
* Math helper class.
*
* @author Nico Bergemann <barracuda415 at yahoo.de>
*/
public class MathX {

public static final double PI_D = Math.PI;
public static final float PI_F = (float) Math.PI;

/**
* You no take constructor!
*/
private MathX() {
}

// float sine function, may use LUT
public static float sin(float a) {
return (float) Math.sin(a);
}

// float cosine function, may use LUT
public static float cos(float a) {
return (float) Math.cos(a);
}

// float tangent function
public static float tan(float a) {
return (float) Math.tan(a);
}

// float atan2 function
public static float atan2(float y, float x) {
return (float) Math.atan2(y, x);
}

// float degrees to radians conversion
public static float toRadians(float angdeg) {
return (float) Math.toRadians(angdeg);
}

// float radians to degrees conversion
public static float toDegrees(float angrad) {
return (float) Math.toDegrees(angrad);
}

// normalizes a float degrees angle to between +180 and -180
public static float normDeg(float a) {
a %= 360;
if (a >= 180) {
a -= 360;
}
if (a < -180) {
a += 360;
}
return a;
}

// normalizes a double degrees angle to between +180 and -180
public static double normDeg(double a) {
a %= 360;
if (a >= 180) {
a -= 360;
}
if (a < -180) {
a += 360;
}
return a;
}

// normalizes a float radians angle to between +π and -π
public static float normRad(float a) {
a %= PI_F * 2;
if (a >= PI_F) {
a -= PI_F * 2;
}
if (a < -PI_F) {
a += PI_F * 2;
}
return a;
}

// normalizes a double radians angle to between +π and -π
public static double normRad(double a) {
a %= PI_D * 2;
if (a >= PI_D) {
a -= PI_D * 2;
}
if (a < -PI_D) {
a += PI_D * 2;
}
return a;
}

// float square root
public static float sqrtf(float f) {
return (float) Math.sqrt(f);
}

// numeric float clamp
public static float clamp(float value, float min, float max) {
return (value < min ? min : (value > max ? max : value));
}

// numeric double clamp
public static double clamp(double value, double min, double max) {
return (value < min ? min : (value > max ? max : value));
}

// numeric integer clamp
public static int clamp(int value, int min, int max) {
return (value < min ? min : (value > max ? max : value));
}

public static float updateRotation(float r1, float r2, float step) {
return r1 + clamp(normDeg(r2 - r1), -step, step);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
** 2016 April 23
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
*/
package com.TheRPGAdventurer.ROTD.util.reflection;

import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.fml.relauncher.ReflectionHelper;

/**
* Interface used to touch Minecraft's private members ( ͡° ͜ʖ ͡°).
*
* @author Nico Bergemann <barracuda415 at yahoo.de>
*/
public interface PrivateAccessor {

static final String[] GUIMAINMENU_SPLASHTEXT = new String[] {"splashText", "field_73975_c"};

default boolean entityIsJumping(EntityLivingBase entity) {
return ReflectionHelper.getPrivateValue(EntityLivingBase.class, entity,
new String[] {"isJumping", "field_70703_bu"});
}

default String mainMenuGetSplashText(GuiMainMenu menu) {
return ReflectionHelper.getPrivateValue(GuiMainMenu.class, menu,
GUIMAINMENU_SPLASHTEXT);
}

default void mainMenuSetSplashText(GuiMainMenu menu, String splash) {
ReflectionHelper.setPrivateValue(GuiMainMenu.class, menu, splash,
GUIMAINMENU_SPLASHTEXT);
}
}

0 comments on commit cd98847

Please sign in to comment.