Skip to content

Commit adf1e71

Browse files
committed
Added clamped icon
1 parent 49ec327 commit adf1e71

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.falsepattern.lib.internal.render;
2+
3+
import com.falsepattern.lib.util.MathUtil;
4+
import lombok.AllArgsConstructor;
5+
import net.minecraft.util.IIcon;
6+
7+
@AllArgsConstructor
8+
public final class ClampedIcon implements IIcon {
9+
private final IIcon delegate;
10+
11+
@Override
12+
public int getIconWidth() {
13+
return delegate.getIconWidth();
14+
}
15+
16+
@Override
17+
public int getIconHeight() {
18+
return delegate.getIconHeight();
19+
}
20+
21+
@Override
22+
public float getMinU() {
23+
return delegate.getMinU();
24+
}
25+
26+
@Override
27+
public float getMaxU() {
28+
return delegate.getMaxU();
29+
}
30+
31+
@Override
32+
public float getMinV() {
33+
return delegate.getMinV();
34+
}
35+
36+
@Override
37+
public float getMaxV() {
38+
return delegate.getMaxV();
39+
}
40+
41+
@Override
42+
public float getInterpolatedU(double textureU) {
43+
return delegate.getInterpolatedU(clampTextureCoordinate(textureU));
44+
}
45+
46+
@Override
47+
public float getInterpolatedV(double textureV) {
48+
return delegate.getInterpolatedV(clampTextureCoordinate(textureV));
49+
}
50+
51+
@Override
52+
public String getIconName() {
53+
return delegate.getIconName();
54+
}
55+
56+
private double clampTextureCoordinate(double textureCoordinate) {
57+
return MathUtil.clamp(textureCoordinate, 0D, 16D);
58+
}
59+
}

src/main/java/com/falsepattern/lib/util/RenderUtil.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@
2121
package com.falsepattern.lib.util;
2222

2323
import com.falsepattern.lib.StableAPI;
24+
import com.falsepattern.lib.internal.render.ClampedIcon;
2425
import com.falsepattern.lib.internal.render.FullTextureIcon;
2526
import lombok.SneakyThrows;
2627
import lombok.experimental.UtilityClass;
2728
import lombok.val;
2829

2930
import net.minecraft.client.Minecraft;
31+
import net.minecraft.client.renderer.RenderBlocks;
3032
import net.minecraft.util.IIcon;
3133
import net.minecraft.util.Timer;
3234
import cpw.mods.fml.relauncher.ReflectionHelper;
3335
import cpw.mods.fml.relauncher.SideOnly;
3436
import org.lwjgl.opengl.GL11;
3537

38+
import java.util.Collections;
39+
3640
import static cpw.mods.fml.relauncher.Side.CLIENT;
3741
import static net.minecraft.client.Minecraft.getMinecraft;
3842

@@ -76,6 +80,20 @@ public static IIcon getFullTextureIcon(String iconName, int width, int height) {
7680
return new FullTextureIcon(iconName, width, height);
7781
}
7882

83+
/**
84+
* Wraps the given icon as a clamped icon.
85+
* <p>
86+
* 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.
87+
* <p>
88+
* This is helpful when using {@link RenderBlocks} but having different bounds.
89+
*
90+
* @param icon The icon to clamp
91+
*/
92+
@StableAPI.Expose(since = "0.10.0")
93+
public static IIcon wrapAsClampedIcon(IIcon icon) {
94+
return new ClampedIcon(icon);
95+
}
96+
7997
/**
8098
* Provides the partial tick between the last and next client tick, in the range of 0 to 1.
8199
* <p>

0 commit comments

Comments
 (0)