Added clamped icon

This commit is contained in:
Ven committed 2023-06-30 11:21:05 +01:00
1 parent 49ec327c97
commit adf1e7146d
2 files changed
+77

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);
}
}
@@ -21,18 +21,22 @@
package com.falsepattern.lib.util;
import com.falsepattern.lib.StableAPI;
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 net.minecraft.client.Minecraft.getMinecraft;
@@ -76,6 +80,20 @@ public final class RenderUtil {
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.10.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>