diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2022-09-07 01:34:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-06 19:34:35 +0200 |
commit | 74b5ef849dea6d9a05e47f0294ccc689069f6f2c (patch) | |
tree | a5528e41ce2b810b82cf99a5acc2c712145b9b59 /src/main/java/gregtech/common | |
parent | 7caea6daefcbffbc102741ed09daac9d6439824d (diff) | |
download | GT5-Unofficial-74b5ef849dea6d9a05e47f0294ccc689069f6f2c.tar.gz GT5-Unofficial-74b5ef849dea6d9a05e47f0294ccc689069f6f2c.tar.bz2 GT5-Unofficial-74b5ef849dea6d9a05e47f0294ccc689069f6f2c.zip |
Fix overly large sprites being used causing some users FPS lag (#1347)
* fix sprite abuse
* Spotless apply for branch fix/sprite-abuse for #1347 (#1348)
Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
* convert gaia spirit
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/common')
4 files changed, 161 insertions, 0 deletions
diff --git a/src/main/java/gregtech/common/GT_Client.java b/src/main/java/gregtech/common/GT_Client.java index 15901703af..af38217e22 100644 --- a/src/main/java/gregtech/common/GT_Client.java +++ b/src/main/java/gregtech/common/GT_Client.java @@ -167,6 +167,7 @@ public class GT_Client extends GT_Proxy implements Runnable { private boolean mFirstTick = false; public static final int ROTATION_MARKER_RESOLUTION = 120; private int mReloadCount; + private float renderTickTime; public GT_Client() { mCapeRenderer = new GT_CapeRenderer(mCapeList); @@ -557,6 +558,8 @@ public class GT_Client extends GT_Proxy implements Runnable { mPollutionRenderer.preLoad(); mPreference = new GT_ClientPreference(GregTech_API.sClientDataFile); + + Materials.initClient(); } @Override @@ -795,6 +798,13 @@ public class GT_Client extends GT_Proxy implements Runnable { } @SubscribeEvent + public void onRenderStart(cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent aEvent) { + if (aEvent.phase == TickEvent.Phase.START) { + renderTickTime = aEvent.renderTickTime; + } + } + + @SubscribeEvent public void onClientTickEvent(cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent aEvent) { if (aEvent.phase == cpw.mods.fml.common.gameevent.TickEvent.Phase.END) { if (changeDetected > 0) changeDetected--; @@ -882,6 +892,16 @@ public class GT_Client extends GT_Proxy implements Runnable { } @Override + public long getAnimationTicks() { + return mAnimationTick; + } + + @Override + public float getPartialRenderTicks() { + return renderTickTime; + } + + @Override public void doSonictronSound(ItemStack aStack, World aWorld, double aX, double aY, double aZ) { if (GT_Utility.isStackInvalid(aStack)) return; String tString = SoundResource.NOTE_HARP.toString(); diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java index 3fb7bdd337..ef82266ed8 100644 --- a/src/main/java/gregtech/common/GT_Proxy.java +++ b/src/main/java/gregtech/common/GT_Proxy.java @@ -2758,6 +2758,14 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler, IG return this.mUniverse == null ? null : this.mUniverse.getSaveHandler().getWorldDirectory(); } + public long getAnimationTicks() { + return 0L; + } + + public float getPartialRenderTicks() { + return 0; + } + public void registerUnificationEntries() { GregTech_API.sUnification.mConfig.save(); GregTech_API.sUnification.mConfig.load(); diff --git a/src/main/java/gregtech/common/render/items/GaiaSpiritRenderer.java b/src/main/java/gregtech/common/render/items/GaiaSpiritRenderer.java new file mode 100644 index 0000000000..12510dce30 --- /dev/null +++ b/src/main/java/gregtech/common/render/items/GaiaSpiritRenderer.java @@ -0,0 +1,37 @@ +package gregtech.common.render.items; + +import gregtech.GT_Mod; +import gregtech.common.render.GT_RenderUtil; +import java.awt.*; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import org.lwjgl.opengl.GL11; + +public class GaiaSpiritRenderer extends GT_GeneratedMaterial_Renderer { + @Override + public void renderRegularItem(ItemRenderType type, ItemStack aStack, IIcon icon, boolean shouldModulateColor) { + long animationTicks = GT_Mod.gregtechproxy.getAnimationTicks(); + float partialTicks = GT_Mod.gregtechproxy.getPartialRenderTicks(); + + if (shouldModulateColor) { + Color color = Color.getHSBColor((animationTicks % 360 + partialTicks) % 180 / 180f, 0.4f, 0.9f); + GL11.glColor3f(color.getRed() / 255.0F, color.getGreen() / 255.0F, color.getBlue() / 255.0F); + } + + if (type.equals(ItemRenderType.INVENTORY)) { + GT_RenderUtil.renderItemIcon(icon, 16.0D, 0.001D, 0.0F, 0.0F, -1.0F); + } else { + ItemRenderer.renderItemIn2D( + Tessellator.instance, + icon.getMaxU(), + icon.getMinV(), + icon.getMinU(), + icon.getMaxV(), + icon.getIconWidth(), + icon.getIconHeight(), + 0.0625F); + } + } +} diff --git a/src/main/java/gregtech/common/render/items/TranscendentMetalRenderer.java b/src/main/java/gregtech/common/render/items/TranscendentMetalRenderer.java new file mode 100644 index 0000000000..0865101826 --- /dev/null +++ b/src/main/java/gregtech/common/render/items/TranscendentMetalRenderer.java @@ -0,0 +1,96 @@ +package gregtech.common.render.items; + +import gregtech.GT_Mod; +import gregtech.api.items.GT_MetaGenerated_Item; +import gregtech.common.render.GT_RenderUtil; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.client.IItemRenderer; +import org.lwjgl.opengl.GL11; + +public class TranscendentMetalRenderer extends GT_GeneratedMaterial_Renderer { + // frameIndex should not have 3 or more frames with same value (unless it's meant to be still) + // otherwise the primitive linear interpolation will render the animation in a pretty sluggish way + private final int[] frameIndex = new int[] { + 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 16, 17, 19, 21, 22, 24, 25, 27, 29, 30, 32, 33, 35, 36, + 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, 49, 48, 47, 46, 45, 44, 43, 42, 40, 39, 38, 36, 35, 33, 32, + 30, 29, 27, 25, 24, 22, 21, 19, 17, 16, 14, 13, 12, 10, 9, 8, 7, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0 + }; + private final float[] frameRotation = new float[] { + 0, 7, 14, 21, 28, 36, 43, 50, 57, 64, + 72, 79, 86, 93, 100, 108, 115, 122, 129, 136, + 144, 151, 158, 165, 172, 180, 187, 194, 201, 208, + 216, 223, 230, 237, 244, 252, 259, 266, 273, 280, + 288, 295, 302, 309, 316, 324, 331, 338, 345, 352, + 360 + }; + private final float[] frameAlpha = new float[] { + 100 / 255f, 106 / 255f, 112 / 255f, 118 / 255f, 124 / 255f, 131 / 255f, 137 / 255f, 143 / 255f, 149 / 255f, + 155 / 255f, + 162 / 255f, 168 / 255f, 174 / 255f, 180 / 255f, 186 / 255f, 193 / 255f, 199 / 255f, 205 / 255f, 211 / 255f, + 217 / 255f, + 224 / 255f, 230 / 255f, 236 / 255f, 242 / 255f, 248 / 255f, 255 / 255f, 248 / 255f, 242 / 255f, 236 / 255f, + 230 / 255f, + 224 / 255f, 217 / 255f, 211 / 255f, 205 / 255f, 199 / 255f, 193 / 255f, 186 / 255f, 180 / 255f, 174 / 255f, + 168 / 255f, + 162 / 255f, 155 / 255f, 149 / 255f, 143 / 255f, 137 / 255f, 131 / 255f, 124 / 255f, 118 / 255f, 112 / 255f, + 106 / 255f, + 100 / 255f + }; + + private static float linearInterpolation(float[] controlPoints, int frameA, int frameB, float partial) { + float a = controlPoints[frameA], b = controlPoints[frameB]; + return a * (1 - partial) + b * partial; + } + + @Override + public void renderRegularItem(ItemRenderType type, ItemStack aStack, IIcon icon, boolean shouldModulateColor) { + GL11.glPushMatrix(); + long animationTicks = GT_Mod.gregtechproxy.getAnimationTicks(); + int frameCurrent = frameIndex[(int) (animationTicks / 2 % frameIndex.length)]; + int frameNext = frameIndex[(int) ((animationTicks + 2) / 2 % frameIndex.length)]; + float partialTicks = GT_Mod.gregtechproxy.getPartialRenderTicks(); + if ((animationTicks & 1) == 1) partialTicks = (partialTicks + 1) / 2; + if (type.equals(IItemRenderer.ItemRenderType.INVENTORY)) { + GL11.glTranslatef(8f, 8f, 0f); + } else { + GL11.glTranslatef(0.5f, 0.5f, 0.0f); + } + GL11.glRotatef(linearInterpolation(frameRotation, frameCurrent, frameNext, partialTicks), 0, 0, 1); + if (type.equals(IItemRenderer.ItemRenderType.INVENTORY)) { + GL11.glTranslatef(-8f, -8f, 0f); + } else { + GL11.glTranslatef(-0.5f, -0.5f, 0.0f); + } + GT_MetaGenerated_Item aItem = (GT_MetaGenerated_Item) aStack.getItem(); + + if (shouldModulateColor) { + short[] tModulation = aItem.getRGBa(aStack); + GL11.glColor4f( + tModulation[0] / 255.0F, + tModulation[1] / 255.0F, + tModulation[2] / 255.0F, + linearInterpolation(frameAlpha, frameCurrent, frameNext, partialTicks)); + } else { + GL11.glColor4f(1f, 1f, 1f, linearInterpolation(frameAlpha, frameCurrent, frameNext, partialTicks)); + } + + if (type.equals(IItemRenderer.ItemRenderType.INVENTORY)) { + GT_RenderUtil.renderItemIcon(icon, 16.0D, 0.001D, 0.0F, 0.0F, -1.0F); + } else { + ItemRenderer.renderItemIn2D( + Tessellator.instance, + icon.getMaxU(), + icon.getMinV(), + icon.getMinU(), + icon.getMaxV(), + icon.getIconWidth(), + icon.getIconHeight(), + 0.0625F); + } + + GL11.glPopMatrix(); + } +} |