mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-12 00:17:49 +00:00
7 files changed
+184
-64
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package com.falsepattern.lib.internal.render;
|
||||
|
||||
import com.falsepattern.lib.util.MathUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
@AllArgsConstructor
|
||||
public final class ClampedIcon implements IIcon {
|
||||
private final IIcon delegate;
|
||||
|
||||
@Override
|
||||
public int getIconWidth() {
|
||||
return delegate.getIconWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconHeight() {
|
||||
return delegate.getIconHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMinU() {
|
||||
return delegate.getMinU();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxU() {
|
||||
return delegate.getMaxU();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMinV() {
|
||||
return delegate.getMinV();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxV() {
|
||||
return delegate.getMaxV();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInterpolatedU(double textureU) {
|
||||
return delegate.getInterpolatedU(clampTextureCoordinate(textureU));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInterpolatedV(double textureV) {
|
||||
return delegate.getInterpolatedV(clampTextureCoordinate(textureV));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIconName() {
|
||||
return delegate.getIconName();
|
||||
}
|
||||
|
||||
private double clampTextureCoordinate(double textureCoordinate) {
|
||||
return MathUtil.clamp(textureCoordinate, 0D, 16D);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.falsepattern.lib.internal.render;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public final class FullTextureIcon implements IIcon {
|
||||
private final String iconName;
|
||||
|
||||
private final int iconWidth;
|
||||
private final int iconHeight;
|
||||
|
||||
@Override
|
||||
public float getMinU() {
|
||||
return 0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMinV() {
|
||||
return 0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxU() {
|
||||
return 1F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxV() {
|
||||
return 1F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInterpolatedU(double textureU) {
|
||||
return (float) textureU / 16F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInterpolatedV(double textureV) {
|
||||
return (float) textureV / 16F;
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,14 @@ package com.falsepattern.lib.util;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@UtilityClass
|
||||
@StableAPI(since = "0.8.2")
|
||||
public class FileUtil {
|
||||
public final class FileUtil {
|
||||
@StableAPI.Expose
|
||||
public static File getMinecraftHome() {
|
||||
return Launch.minecraftHome == null ? new File(".") : Launch.minecraftHome;
|
||||
|
||||
@@ -23,6 +23,7 @@ package com.falsepattern.lib.util;
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.val;
|
||||
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
@@ -32,7 +33,7 @@ import java.util.Map;
|
||||
|
||||
import static lombok.AccessLevel.PRIVATE;
|
||||
|
||||
@NoArgsConstructor(access = PRIVATE)
|
||||
@UtilityClass
|
||||
@StableAPI(since = "0.8.0")
|
||||
public final class LangUtil {
|
||||
@StableAPI.Expose
|
||||
|
||||
@@ -22,12 +22,14 @@ package com.falsepattern.lib.util;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.compat.Vec3i;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
@StableAPI(since = "0.10.0")
|
||||
public class MathUtil {
|
||||
public final class MathUtil {
|
||||
@StableAPI.Expose
|
||||
public static final float SQRT_2 = sqrt(2.0F);
|
||||
/**
|
||||
@@ -621,4 +623,4 @@ public class MathUtil {
|
||||
x = x ^ x >>> 16;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,25 +21,90 @@
|
||||
package com.falsepattern.lib.util;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import lombok.NoArgsConstructor;
|
||||
import com.falsepattern.lib.internal.render.ClampedIcon;
|
||||
import com.falsepattern.lib.internal.render.FullTextureIcon;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.val;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Timer;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static cpw.mods.fml.relauncher.Side.CLIENT;
|
||||
import static lombok.AccessLevel.PRIVATE;
|
||||
import static net.minecraft.client.Minecraft.getMinecraft;
|
||||
|
||||
@SideOnly(CLIENT)
|
||||
@NoArgsConstructor(access = PRIVATE)
|
||||
@UtilityClass
|
||||
@StableAPI(since = "0.8.0")
|
||||
public final class RenderUtil {
|
||||
private final static Timer MINECRAFT_TIMER = getMinecraftTimer();
|
||||
private static final Timer MINECRAFT_TIMER = getMinecraftTimer();
|
||||
|
||||
/**
|
||||
* Sets the OpenGL translation, relative to the player's position.
|
||||
* <p>
|
||||
* This is useful for rendering things that are not part of the world mesh, but should be rendered as if they were.
|
||||
* <p>
|
||||
* It's good practice to make this call inside a {@link GL11#glPushMatrix() push}/{@link GL11#glPopMatrix() pop} matrix block.
|
||||
*/
|
||||
@StableAPI.Expose(since = "0.12.0")
|
||||
public static void setGLTranslationRelativeToPlayer() {
|
||||
val player = getMinecraft().thePlayer;
|
||||
val partialTick = partialTick();
|
||||
|
||||
val offsetX = (float) (player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTick);
|
||||
val offsetY = (float) (player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTick);
|
||||
val offsetZ = (float) (player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTick);
|
||||
|
||||
GL11.glTranslatef(-offsetX, -offsetY, -offsetZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a texture icon with the given name and dimensions.
|
||||
* <p>
|
||||
* This is useful for rendering textures that are not part of the Minecraft texture atlas.
|
||||
*
|
||||
* @param iconName The icon name
|
||||
* @param width The icon width in pixels
|
||||
* @param height The icon height in pixels
|
||||
* @return The full resolution texture icon.
|
||||
*/
|
||||
@StableAPI.Expose(since = "0.10.0")
|
||||
public static IIcon getFullTextureIcon(String iconName, int width, int height) {
|
||||
return new FullTextureIcon(iconName, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the given icon as a clamped icon.
|
||||
* <p>
|
||||
* A clamped icon will clamp the coordinates given to {@link IIcon#getInterpolatedU(double)} and {@link IIcon#getInterpolatedV(double)} to the range of 0 to 16.
|
||||
* <p>
|
||||
* This is helpful when using {@link RenderBlocks} but having different bounds.
|
||||
*
|
||||
* @param icon The icon to clamp
|
||||
*/
|
||||
@StableAPI.Expose(since = "0.12.0")
|
||||
public static IIcon wrapAsClampedIcon(IIcon icon) {
|
||||
return new ClampedIcon(icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the partial tick between the last and next client tick, in the range of 0 to 1.
|
||||
* <p>
|
||||
* Sometimes referred to as 'subTick', it is used mostly for interpolation in rendering.
|
||||
*
|
||||
* @return The current partial tick
|
||||
*/
|
||||
@StableAPI.Expose
|
||||
public static float partialTick() {
|
||||
return MINECRAFT_TIMER.renderPartialTicks;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
@SneakyThrows
|
||||
@@ -48,59 +113,4 @@ public final class RenderUtil {
|
||||
timerField.setAccessible(true);
|
||||
return (Timer) timerField.get(getMinecraft());
|
||||
}
|
||||
|
||||
@StableAPI.Expose(since = "0.10.0")
|
||||
public static IIcon getFullTextureIcon(String iconName, int width, int height) {
|
||||
return new IIcon() {
|
||||
@Override
|
||||
public int getIconWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMinU() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxU() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInterpolatedU(double u) {
|
||||
return (float) (u / 16D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMinV() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxV() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInterpolatedV(double v) {
|
||||
return (float) (v / 16D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIconName() {
|
||||
return iconName;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static float partialTick() {
|
||||
return MINECRAFT_TIMER.renderPartialTicks;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
package com.falsepattern.lib.util;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.val;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -34,8 +35,9 @@ import java.nio.charset.StandardCharsets;
|
||||
/**
|
||||
* A utility class for reading resources in many ways.
|
||||
*/
|
||||
@UtilityClass
|
||||
@StableAPI(since = "0.6.0")
|
||||
public class ResourceUtil {
|
||||
public final class ResourceUtil {
|
||||
|
||||
/**
|
||||
* Reads a resource as a string, using the {@link StandardCharsets#UTF_8} charset, from a specific jar file. See
|
||||
|
||||
Reference in new issue
Block a user