Add missed files
This commit is contained in:
@@ -1,2 +1,18 @@
|
||||
package me.hypherionmc.craterlib.util;public class BlockStateUtils {
|
||||
package me.hypherionmc.craterlib.util;
|
||||
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
public class BlockStateUtils {
|
||||
|
||||
public static ToIntFunction<BlockState> createLightLevelFromLitBlockState(int litLevel) {
|
||||
return state -> state.getValue(BlockStateProperties.LIT) ? litLevel : 0;
|
||||
}
|
||||
|
||||
public static ToIntFunction<BlockState> createLightLevelFromPoweredBlockState(int litLevel) {
|
||||
return state -> state.getValue(BlockStateProperties.POWERED) ? litLevel : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,26 +1,26 @@
|
||||
package me.hypherionmc.hyperlighting.utils;
|
||||
package me.hypherionmc.craterlib.util;
|
||||
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
|
||||
public class LangUtils {
|
||||
|
||||
public static BaseText getTooltipTitle(String key) {
|
||||
return new LiteralText(Formatting.YELLOW + new TranslatableText(key).getString());
|
||||
public static Component getTooltipTitle(String key) {
|
||||
return new TextComponent(ChatFormatting.YELLOW + new TranslatableComponent(key).getString());
|
||||
}
|
||||
|
||||
public static String resolveTranslation(String key) {
|
||||
return new TranslatableText(key).getString();
|
||||
return new TranslatableComponent(key).getString();
|
||||
}
|
||||
|
||||
public static BaseText getTranslation(String key) {
|
||||
return new TranslatableText(key);
|
||||
public static Component getTranslation(String key) {
|
||||
return new TranslatableComponent(key);
|
||||
}
|
||||
|
||||
public static BaseText makeComponent(String text) {
|
||||
return new LiteralText(text);
|
||||
public static Component makeComponent(String text) {
|
||||
return new TranslatableComponent(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,21 +1,37 @@
|
||||
package me.hypherionmc.hyperlighting.utils;
|
||||
package me.hypherionmc.craterlib.util;
|
||||
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public class MathUtils {
|
||||
|
||||
public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape shape) {
|
||||
VoxelShape[] buffer = new VoxelShape[]{ shape, VoxelShapes.empty() };
|
||||
VoxelShape[] buffer = new VoxelShape[]{ shape, Shapes.empty() };
|
||||
|
||||
int times = (to.ordinal() - from.ordinal() + 4) % 4;
|
||||
for (int i = 0; i < times; i++) {
|
||||
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.union(buffer[1], VoxelShapes.cuboid(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
|
||||
buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.box(1-maxZ, minY, minX, 1-minZ, maxY, maxX)));
|
||||
buffer[0] = buffer[1];
|
||||
buffer[1] = VoxelShapes.empty();
|
||||
buffer[1] = Shapes.empty();
|
||||
}
|
||||
return buffer[0];
|
||||
}
|
||||
|
||||
public static void writeBlockPosToNBT(BlockPos pos, CompoundTag tag) {
|
||||
tag.putInt("block_x", pos.getX());
|
||||
tag.putInt("block_y", pos.getY());
|
||||
tag.putInt("block_z", pos.getZ());
|
||||
}
|
||||
|
||||
public static BlockPos readBlockPosFromNBT(CompoundTag tag) {
|
||||
int x, y, z;
|
||||
x = tag.getInt("block_x");
|
||||
y = tag.getInt("block_y");
|
||||
z = tag.getInt("block_z");
|
||||
return new BlockPos(x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,2 +1,41 @@
|
||||
package me.hypherionmc.craterlib.util;public class OptifineUtils {
|
||||
package me.hypherionmc.craterlib.util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class OptifineUtils {
|
||||
|
||||
private static boolean hasOptifine = false;
|
||||
|
||||
public static void checkOptifine() {
|
||||
try {
|
||||
Class ofConfigClass = Class.forName("net.optifine.Config");
|
||||
hasOptifine = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
// Optifine is probably not present. Ignore the error
|
||||
hasOptifine = false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
hasOptifine = false;
|
||||
}
|
||||
|
||||
public static boolean isRenderRegions() {
|
||||
try {
|
||||
Class ofConfigClass = Class.forName("net.optifine.Config");
|
||||
Method rrField = ofConfigClass.getMethod("isRenderRegions");
|
||||
return (boolean) rrField.invoke(null);
|
||||
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
||||
// Optifine is probably not present. Ignore the error
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasOptifine() {
|
||||
return hasOptifine;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,2 +1,52 @@
|
||||
package me.hypherionmc.craterlib.util;public class RenderUtils {
|
||||
package me.hypherionmc.craterlib.util;
|
||||
|
||||
import com.mojang.math.Vector4f;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
|
||||
public class RenderUtils {
|
||||
|
||||
public static Vector4f colorIntToRGBA(int color) {
|
||||
float a = 1.0F;
|
||||
float r = (color >> 16 & 0xFF) / 255.0F;
|
||||
float g = (color >> 8 & 0xFF) / 255.0F;
|
||||
float b = (color & 0xFF) / 255.0F;
|
||||
|
||||
return new Vector4f(r, g, b, a);
|
||||
}
|
||||
|
||||
public static Component getFluidAmount(long amount, long capacity) {
|
||||
amount = amount / 81;
|
||||
capacity = capacity / 81;
|
||||
String text = "" + (int) (((float) amount / capacity) * 100);
|
||||
return amount > 0 ? new TextComponent(ChatFormatting.AQUA + text + "%") : new TextComponent(text + "%");
|
||||
}
|
||||
|
||||
public static Component getTimeDisplayString(double value) {
|
||||
long seconds = Math.round((value / 20));
|
||||
long minutes = Math.round(seconds / 60);
|
||||
if (seconds >= 60) {
|
||||
String appendString = (minutes == 1) ? "Minute" : "Minutes";
|
||||
String doSeconds = ((seconds - (minutes * 60)) > 0) ? ", " + (seconds - (minutes * 60)) + " Seconds" : "";
|
||||
return new TextComponent(minutes + " " + appendString + doSeconds);
|
||||
} else {
|
||||
return new TextComponent(seconds + " Seconds");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ARGB32 {
|
||||
public static int alpha(int pPackedColor) {
|
||||
return pPackedColor >>> 24;
|
||||
}
|
||||
public static int red(int pPackedColor) {
|
||||
return pPackedColor >> 16 & 255;
|
||||
}
|
||||
public static int green(int pPackedColor) {
|
||||
return pPackedColor >> 8 & 255;
|
||||
}
|
||||
public static int blue(int pPackedColor) {
|
||||
return pPackedColor & 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user