Files
FalsePatternLib/src/main/java/com/falsepattern/lib/util/RenderUtil.java
T

106 lines
3.1 KiB
Java
Raw Normal View History

2022-07-31 20:41:56 +02:00
/*
2022-07-30 15:21:11 +02:00
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2022-06-12 11:56:22 +02:00
package com.falsepattern.lib.util;
2022-06-12 11:58:13 +02:00
import com.falsepattern.lib.StableAPI;
2022-07-30 23:26:25 +02:00
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import lombok.val;
2022-06-12 11:56:22 +02:00
import net.minecraft.client.Minecraft;
2022-07-30 23:26:25 +02:00
import net.minecraft.util.IIcon;
2022-06-12 11:56:22 +02:00
import net.minecraft.util.Timer;
2022-07-30 23:26:25 +02:00
import cpw.mods.fml.relauncher.ReflectionHelper;
import cpw.mods.fml.relauncher.SideOnly;
2022-06-12 11:56:22 +02:00
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)
2022-06-12 11:58:13 +02:00
@StableAPI(since = "0.8.0")
2022-06-12 11:56:22 +02:00
public final class RenderUtil {
private final static Timer MINECRAFT_TIMER = getMinecraftTimer();
2022-08-06 13:12:55 +02:00
@StableAPI.Expose
2022-06-12 11:56:22 +02:00
@SneakyThrows
private static Timer getMinecraftTimer() {
val timerField = ReflectionHelper.findField(Minecraft.class, "timer", "field_71428_T");
timerField.setAccessible(true);
return (Timer) timerField.get(getMinecraft());
}
2022-07-30 23:26:25 +02:00
@StableAPI(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;
}
};
}
2022-08-06 13:12:55 +02:00
@StableAPI.Expose
2022-06-12 11:56:22 +02:00
public static float partialTick() {
return MINECRAFT_TIMER.renderPartialTicks;
}
}