finalbeta/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java

106 lines
3.1 KiB
Java

package xyz.pixelatedw.finalbeta;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.time.Duration;
import java.util.HashMap;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemInstance;
import net.minecraft.item.ItemType;
public class WyHelper {
private static final Minecraft INSTANCE;
public static final String SPAWN_TIME_TAG = "SpawnTime";
public static final String PLAY_TIME_TAG = "PlayTime";
public static long playTime;
// Look if they're allowed to hold all block and item data in fucking arrays
// I am also allowed to abuse maps to extend the shitty metadata excuse
// doors have ok ? I don't even care about the overhead at this point.
public static final HashMap<Integer, Long> DOOR_UPDATES = new HashMap<>();
public static final HashMap<Integer, Boolean> DOOR_STATES = new HashMap<>();
static {
INSTANCE = getInstance();
}
public static Field getField(Class clz, String... names) {
for (String name : names) {
try {
Field field = clz.getDeclaredField(name);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException ex) {
continue;
}
}
return null;
}
public static Method getMethod(Class clz, String[] names, Class<?>... params) {
for (String name : names) {
try {
Method method = clz.getDeclaredMethod(name, params);
method.setAccessible(true);
return method;
} catch (NoSuchMethodException ex) {
continue;
}
}
return null;
}
public static Minecraft getInstance() {
if (INSTANCE != null) {
return INSTANCE;
} else {
try {
return (Minecraft) getField(Minecraft.class, "instance", "field_2791").get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
return null;
}
}
}
public static long getRealDaysPlayed() {
long seconds = WyHelper.playTime / 20;
return Duration.ofSeconds(seconds).toDays();
}
public static long getGameDaysPlayed() {
long seconds = WyHelper.getInstance().level.getLevelTime() / 20;
return Duration.ofSeconds(seconds).toMinutes() / 20;
}
public static boolean isDebug() {
return ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
}
public static float lerp(float delta, float start, float end) {
return start + delta * (end - start);
}
public static float clamp(float val, float min, float max) {
return val < min ? min : Math.min(val, max);
}
public static void cheatCommand(Player player) {
player.dropItem(new ItemInstance(ItemType.pickaxeIron, 1, 100));
player.dropItem(new ItemInstance(ItemType.pickaxeIron, 1, 150));
player.dropItem(new ItemInstance(ItemType.pickaxeDiamond, 1, 150));
// player.dropItem(new ItemInstance(Tile.WOOD, 64));
// player.dropItem(new ItemInstance(ItemType.snowball, 60));
player.level.setLevelTime(0);
player.level.getProperties().setRaining(false);
player.level.getProperties().setRainTime(0);
player.level.getProperties().setThundering(false);
player.level.getProperties().setThunderTime(0);
}
}