Skip to content

Commit

Permalink
Merge pull request #75 from EssentialGG/feature/update-preprocessor
Browse files Browse the repository at this point in the history
Update preprocessor

Latest preprocessor has two new features which UC can make good use of:
1. "Strict extra mapping files" allow (well, require, with automatic inference where possible) one to specify exact types for method mappings (e.g.  `translate(DDD)V` to `translated()`, but  `translate(FFF)V` to  `translatef()`), allowing us to use extra mappings for a bunch more things which previously had to use preprocessor statements.
2. It will now try to infer class mappings for srg-era Minecraft versions based on shared method/field names, allowing us to get rid of a bunch of manually entered class mappings.

It also gained a `cleanupUnnecessaryMappings` task which will automatically remove any mapping entries which don't do anything (be it because of point 2, or because they were broken or redundant to begin with).

This also fixes `UGraphics.blendEquation` inappropriately bypassing `GlStateManager` on 1.12.2.
  • Loading branch information
Johni0702 authored Aug 6, 2024
2 parents 0696479 + 6841155 commit 34cec8d
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 103 deletions.
4 changes: 3 additions & 1 deletion root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ plugins {
version = versionFromBuildIdAndBranch()

preprocess {
strictExtraMappings.set(true)

val fabric12100 = createNode("1.21-fabric", 12100, "srg")
val fabric12006 = createNode("1.20.6-fabric", 12006, "srg")
val forge12004 = createNode("1.20.4-forge", 12004, "srg")
Expand Down Expand Up @@ -58,5 +60,5 @@ preprocess {
fabric11701.link(fabric11602, file("versions/1.17.1-1.16.2.txt"))
fabric11602.link(forge11602)
forge11602.link(forge11202, file("versions/1.16.2-1.12.2.txt"))
forge11202.link(forge10809, file("versions/1.12.2-1.8.9.txt"))
forge11202.link(forge10809)
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pluginManagement {
maven("https://repo.essential.gg/repository/maven-public")
}
plugins {
val egtVersion = "0.5.0"
val egtVersion = "0.6.2"
id("gg.essential.multi-version.root") version egtVersion
id("gg.essential.multi-version.api-validation") version egtVersion
}
Expand Down
67 changes: 6 additions & 61 deletions src/main/java/gg/essential/universal/UGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import gg.essential.universal.vertex.UVertexConsumer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
Expand Down Expand Up @@ -70,19 +71,15 @@

//#if MC>=11502
//$$ import com.mojang.blaze3d.platform.GlStateManager;
//$$ import net.minecraft.client.renderer.BufferBuilder;
//$$ import net.minecraft.client.renderer.texture.NativeImage;
//$$ import java.io.ByteArrayInputStream;
//$$ import java.io.ByteArrayOutputStream;
//#else
import static org.lwjgl.opengl.GL14.glBlendEquation;
//#endif

//#if MC>=11400
//$$ import net.minecraft.client.renderer.texture.Texture;
//#else
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.ITextureObject;
//#endif

Expand Down Expand Up @@ -232,8 +229,6 @@ public static void enableBlend() {
public static void disableTexture2D() {
//#if MC>=11904
//$$ // no-op
//#elseif MC>=11502
//$$ RenderSystem.disableTexture();
//#else
GlStateManager.disableTexture2D();
//#endif
Expand All @@ -242,12 +237,8 @@ public static void disableTexture2D() {

public static void disableAlpha() {
//#if MC<11700
//#if MC>=11502
//$$ RenderSystem.disableAlphaTest();
//#else
GlStateManager.disableAlpha();
//#endif
//#endif
}

public static void shadeModel(int mode) {
Expand All @@ -257,19 +248,15 @@ public static void shadeModel(int mode) {
}

public static void blendEquation(int equation) {
//#if MC>=11500
//$$ RenderSystem.blendEquation(equation);
//#if MC>=10900
//$$ GlStateManager.glBlendEquation(equation);
//#else
glBlendEquation(equation);
org.lwjgl.opengl.GL14.glBlendEquation(equation);
//#endif
}

public static void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFactorAlpha, int dstFactorAlpha) {
//#if MC>=11502
//$$ RenderSystem.blendFuncSeparate(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
//#else
GlStateManager.tryBlendFuncSeparate(srcFactor, dstFactor, srcFactorAlpha, dstFactorAlpha);
//#endif
}

/**
Expand All @@ -284,8 +271,6 @@ public static void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFac
public static void enableTexture2D() {
//#if MC>=11904
//$$ // no-op
//#elseif MC>=11502
//$$ RenderSystem.enableTexture();
//#else
GlStateManager.enableTexture2D();
//#endif
Expand All @@ -301,12 +286,8 @@ public static void deleteTexture(int glTextureId) {

public static void enableAlpha() {
//#if MC<11700
//#if MC>=11502
//$$ RenderSystem.enableAlphaTest();
//#else
GlStateManager.enableAlpha();
//#endif
//#endif
}

public static void configureTexture(int glTextureId, Runnable block) {
Expand Down Expand Up @@ -651,31 +632,19 @@ public static String glGetProgramInfoLog(int program, int maxLen) {
}

public static void color4f(float red, float green, float blue, float alpha) {
//#if MC<11502
GlStateManager.color(red, green, blue, alpha);
//#else
//$$ RenderSystem.color4f(red, green, blue, alpha);
//#endif
}

public static void directColor3f(float red, float green, float blue) {
//#if MC>=11700
//$$ color4f(red, green, blue, 1f);
//#else
//#if MC<11502
GlStateManager.color(red, green, blue);
//#else
//$$ RenderSystem.color3f(red, green, blue);
//#endif
//#endif
}

public static void enableDepth() {
//#if MC<11502
GlStateManager.enableDepth();
//#else
//$$ RenderSystem.enableDepthTest();
//#endif
}

public static void depthFunc(int mode) {
Expand All @@ -687,11 +656,7 @@ public static void depthMask(boolean flag) {
}

public static void disableDepth() {
//#if MC<11502
GlStateManager.disableDepth();
//#else
//$$ RenderSystem.disableDepthTest();
//#endif
}

//#if MC>=11700
Expand Down Expand Up @@ -1125,43 +1090,23 @@ public static void popMatrix() {
}

public static void translate(float x, float y, float z) {
//#if MC>=11502
//$$ RenderSystem.translatef(x, y, z);
//#else
translate(x, y, (double) z);
//#endif
GlStateManager.translate(x, y, z);
}

public static void translate(double x, double y, double z) {
//#if MC>=11502
//$$ RenderSystem.translated(x, y, z);
//#else
GlStateManager.translate(x, y, z);
//#endif
}

public static void rotate(float angle, float x, float y, float z) {
//#if MC>=11502
//$$ RenderSystem.rotatef(angle, x, y, z);
//#else
GlStateManager.rotate(angle, x, y, z);
//#endif
}

public static void scale(float x, float y, float z) {
//#if MC>=11502
//$$ RenderSystem.scalef(x, y, z);
//#else
scale(x, y, (double) z);
//#endif
GlStateManager.scale(x, y, z);
}

public static void scale(double x, double y, double z) {
//#if MC>=11502
//$$ RenderSystem.scaled(x, y, z);
//#else
GlStateManager.scale(x, y, z);
//#endif
}
}
//#endif
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/gg/essential/universal/UMatrixStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ class UMatrixStack private constructor(
//#if MC>=11700
//#if MC>=12005
//$$ RenderSystem.getModelViewStack().mul(stack.last.model)
//#elseif MC>=11800
//$$ // FIXME preprocessor bug: should remap the intermediary name to yarn no problem
//$$ RenderSystem.getModelViewStack().multiplyPositionMatrix(stack.last.model)
//#else
//$$ RenderSystem.getModelViewStack().method_34425(stack.last.model)
//#endif
Expand Down
5 changes: 0 additions & 5 deletions src/main/kotlin/gg/essential/universal/UPacket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import net.minecraft.network.play.server.S02PacketChat
//#if MC>=11901
//#else
//#if MC>=11900
//$$ // FIXME preprocessor bug: remaps alias references in code to remapped type, so we can't keep the alias
//#if FABRIC
//$$ import net.minecraft.network.message.MessageType as MCMessageType
//#else
//$$ import net.minecraft.network.chat.ChatType
//#endif
//$$ import net.minecraft.util.registry.Registry
//$$ import net.minecraft.util.registry.RegistryKey
//$$
Expand Down
11 changes: 0 additions & 11 deletions versions/1.12.2-1.8.9.txt

This file was deleted.

35 changes: 14 additions & 21 deletions versions/1.16.2-1.12.2.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
net.minecraft.client.audio.SimpleSound net.minecraft.client.audio.PositionedSoundRecord
net.minecraft.client.audio.SimpleSound master() func_194007_a()
net.minecraft.util.SoundEvents BLOCK_NOTE_BLOCK_PLING net.minecraft.init.SoundEvents BLOCK_NOTE_PLING
net.minecraft.util.SoundEvents net.minecraft.init.SoundEvents
net.minecraft.client.renderer.texture.Texture net.minecraft.client.renderer.texture.AbstractTexture
net.minecraft.resources.IResourceManager net.minecraft.client.resources.IResourceManager
net.minecraft.client.renderer.texture.TextureUtil prepareImage() allocateTexture()
net.minecraft.util.math.vector.Matrix3f org.lwjgl.util.vector.Matrix3f
net.minecraft.util.math.vector.Matrix4f org.lwjgl.util.vector.Matrix4f
net.minecraft.util.math.vector.Matrix4f write() org.lwjgl.util.vector.Matrix4f store()
net.minecraft.util.math.vector.Matrix4f write(Ljava/nio/FloatBuffer;)V store(Ljava/nio/FloatBuffer;)Lorg/lwjgl/util/vector/Matrix;
net.minecraft.util.math.vector.Quaternion org.lwjgl.util.vector.Quaternion
net.minecraft.util.math.vector.Vector3f org.lwjgl.util.vector.Vector3f
net.minecraft.util.math.vector.Vector4f org.lwjgl.util.vector.Vector4f
net.minecraft.client.gui.screen.Screen net.minecraft.client.gui.GuiScreen
net.minecraft.client.gui.widget.Widget net.minecraft.client.gui.GuiButton
net.minecraft.client.renderer.entity.RenderPlayer net.minecraft.client.renderer.entity.PlayerRenderer
net.minecraft.entity.player.PlayerEntity net.minecraft.entity.player.EntityPlayer
com.mojang.blaze3d.systems.RenderSystem net.minecraft.client.renderer.GlStateManager
com.mojang.blaze3d.systems.RenderSystem translated() translate(DDD)V
com.mojang.blaze3d.systems.RenderSystem translatef() translate(FFF)V
com.mojang.blaze3d.systems.RenderSystem rotatef() rotate(FFFF)V
com.mojang.blaze3d.systems.RenderSystem scalef() scale(FFF)V
com.mojang.blaze3d.systems.RenderSystem scaled() scale(DDD)V
com.mojang.blaze3d.systems.RenderSystem color3f() color(FFF)V
com.mojang.blaze3d.systems.RenderSystem color4f() color(FFFF)V
com.mojang.blaze3d.systems.RenderSystem enableDepthTest() enableDepth()
com.mojang.blaze3d.systems.RenderSystem disableDepthTest() disableDepth()
com.mojang.blaze3d.systems.RenderSystem enableAlphaTest() enableAlpha()
com.mojang.blaze3d.systems.RenderSystem disableAlphaTest() disableAlpha()
com.mojang.blaze3d.systems.RenderSystem blendEquation() glBlendEquation()
com.mojang.blaze3d.systems.RenderSystem blendFuncSeparate() tryBlendFuncSeparate()
com.mojang.blaze3d.systems.RenderSystem activeTexture() net.minecraft.client.renderer.GlStateManager setActiveTexture()
com.mojang.blaze3d.systems.RenderSystem enableTexture() net.minecraft.client.renderer.GlStateManager enableTexture2D()
com.mojang.blaze3d.systems.RenderSystem disableTexture() net.minecraft.client.renderer.GlStateManager disableTexture2D()
net.minecraft.client.renderer.vertex.VertexFormat hasUV() hasUvOffset()
net.minecraft.client.renderer.vertex.VertexFormatElement$Usage net.minecraft.client.renderer.vertex.VertexFormatElement$EnumUsage
net.minecraft.client.renderer.vertex.DefaultVertexFormats POSITION_TEX_LIGHTMAP_COLOR POSITION_TEX_LMAP_COLOR
net.minecraft.client.renderer.entity.PlayerRenderer net.minecraft.client.renderer.entity.RenderPlayer
net.minecraft.client.world.ClientWorld net.minecraft.client.multiplayer.WorldClient
net.minecraft.client.entity.player.ClientPlayerEntity net.minecraft.client.entity.EntityPlayerSP
net.minecraft.client.network.play.ClientPlayNetHandler net.minecraft.client.network.NetHandlerPlayClient
net.minecraft.potion.EffectInstance net.minecraft.potion.PotionEffect
net.minecraft.util.text.StringTextComponent net.minecraft.util.text.TextComponentString
net.minecraft.client.GameSettings net.minecraft.client.settings.GameSettings
net.minecraft.client.gui.NewChatGui net.minecraft.client.gui.GuiNewChat
net.minecraft.client.gui.screen.MainMenuScreen net.minecraft.client.gui.GuiMainMenu
net.minecraft.network.play.server.SChatPacket net.minecraft.network.play.server.SPacketChat
1 change: 1 addition & 0 deletions versions/1.17.1-1.16.2.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
com.mojang.blaze3d.platform.TextureUtil net.minecraft.client.texture.TextureUtil
com.mojang.blaze3d.platform.TextureUtil prepareImage() net.minecraft.client.texture.TextureUtil allocate()
com.mojang.blaze3d.platform.GlStateManager com.mojang.blaze3d.platform.GlStateManager
com.mojang.blaze3d.platform.GlStateManager glCreateProgram() createProgram()
com.mojang.blaze3d.platform.GlStateManager _glUseProgram() useProgram()
com.mojang.blaze3d.platform.GlStateManager glCreateShader() createShader()
Expand Down

0 comments on commit 34cec8d

Please sign in to comment.