diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-10-25 13:17:00 -0700 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-10-25 13:17:00 -0700 |
commit | 730ec4f0faaf99e231279fdc026566f9970afb23 (patch) | |
tree | e84bd462ed7c482e958924d242853f5904f8e51f | |
parent | ec4c5aebf3b5b5af872c6b168c02bedd2bd5a9e3 (diff) | |
download | Iceberg-730ec4f0faaf99e231279fdc026566f9970afb23.tar.gz Iceberg-730ec4f0faaf99e231279fdc026566f9970afb23.tar.bz2 Iceberg-730ec4f0faaf99e231279fdc026566f9970afb23.zip |
Fixed crash issue in creative inventory. Fixed tooltip rendering issue.
Enabled mixins.
-rw-r--r-- | build.gradle | 10 | ||||
-rw-r--r-- | gradle.properties | 2 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java | 18 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java | 32 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java | 10 | ||||
-rw-r--r-- | src/main/resources/fabric.mod.json | 3 | ||||
-rw-r--r-- | src/main/resources/iceberg.mixins.json | 3 |
7 files changed, 59 insertions, 19 deletions
diff --git a/build.gradle b/build.gradle index c037977..163ecc9 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { sourceCompatibility = JavaVersion.VERSION_16 targetCompatibility = JavaVersion.VERSION_16 -archivesBaseName = project.name + '-' + project.mcVersion +archivesBaseName = project.name + '-' + project.mcVersion + '-fabric' sourceSets.main.java.srcDirs += 'java' sourceSets.main.resources.srcDirs += 'resources' @@ -37,6 +37,14 @@ loom { accessWidenerPath = file("src/main/resources/${project.name.toLowerCase()}.accesswidener") } +processResources { + inputs.property 'version', project.version + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" it.options.release = 16 diff --git a/gradle.properties b/gradle.properties index bf173b9..5d215d0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.daemon=false name=${rootProject.name} group=com.anthonyhilyard.${name.toLowerCase()} author=anthonyhilyard -version=1.0.16 +version=1.0.17 mcVersion=1.17.1 fabricVersion=0.39.2+1.17 diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java index 225499f..fdd3c9d 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java @@ -11,7 +11,6 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @@ -22,6 +21,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; @Mixin(Screen.class) @@ -35,17 +35,19 @@ public class ScreenMixin extends AbstractContainerEventHandler private final List<GuiEventListener> children = Lists.newArrayList(); @SuppressWarnings("unchecked") - @Inject(method = "renderTooltipInternal", - at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;blitOffset:F", ordinal = 2, shift = Shift.AFTER), - locals = LocalCapture.CAPTURE_FAILEXCEPTION) + @Inject(method = "renderTooltipInternal", at = @At(value = "TAIL"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) private void renderTooltipInternal(PoseStack poseStack, List<ClientTooltipComponent> components, int x, int y, CallbackInfo info, int tooltipWidth, int tooltipHeight, int postX, int postY) { - if (!components.isEmpty()) + if ((Screen)(Object)this instanceof AbstractContainerScreen) { - if ((Screen)(Object)this instanceof AbstractContainerScreen) + if (!components.isEmpty()) { - ItemStack tooltipStack = ((AbstractContainerScreen<AbstractContainerMenu>)(Object)this).hoveredSlot.getItem(); - RenderTooltipEvents.POST.invoker().onPost(tooltipStack, components, poseStack, x, y, font, tooltipWidth, tooltipHeight, false); + Slot hoveredSlot = ((AbstractContainerScreen<AbstractContainerMenu>)(Object)this).hoveredSlot; + if (hoveredSlot != null) + { + ItemStack tooltipStack = hoveredSlot.getItem(); + RenderTooltipEvents.POST.invoker().onPost(tooltipStack, components, poseStack, x, y, font, tooltipWidth, tooltipHeight, false); + } } } } diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java index f9395d3..9e7842f 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java @@ -4,12 +4,31 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.renderer.GameRenderer; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.BufferUploader; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.math.Matrix4f; public class GuiHelper { + public static void drawGradientRect(Matrix4f mat, int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) + { + RenderSystem.enableDepthTest(); + RenderSystem.disableTexture(); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.setShader(GameRenderer::getPositionColorShader); + + Tesselator tessellator = Tesselator.getInstance(); + BufferBuilder bufferBuilder = tessellator.getBuilder(); + drawGradientRect(mat, bufferBuilder, left, top, right, bottom, zLevel, startColor, endColor); + bufferBuilder.end(); + BufferUploader.end(bufferBuilder); + + RenderSystem.disableBlend(); + RenderSystem.enableTexture(); + } + public static void drawGradientRect(Matrix4f mat, BufferBuilder bufferBuilder, int left, int top, int right, int bottom, int zLevel, int startColor, int endColor) { float startAlpha = (float)(startColor >> 24 & 255) / 255.0F; @@ -20,6 +39,7 @@ public class GuiHelper float endRed = (float)(endColor >> 16 & 255) / 255.0F; float endGreen = (float)(endColor >> 8 & 255) / 255.0F; float endBlue = (float)(endColor & 255) / 255.0F; + bufferBuilder.vertex(mat, right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); bufferBuilder.vertex(mat, left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); bufferBuilder.vertex(mat, left, bottom, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex(); @@ -44,12 +64,12 @@ public class GuiHelper RenderSystem.setShader(GameRenderer::getPositionColorShader); Tesselator tessellator = Tesselator.getInstance(); - BufferBuilder buffer = tessellator.getBuilder(); - buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - buffer.vertex(mat, right, top, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex(); - buffer.vertex(mat, left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); - buffer.vertex(mat, left, bottom, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); - buffer.vertex(mat, right, bottom, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex(); + BufferBuilder bufferBuilder = tessellator.getBuilder(); + bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); + bufferBuilder.vertex(mat, right, top, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex(); + bufferBuilder.vertex(mat, left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + bufferBuilder.vertex(mat, left, bottom, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + bufferBuilder.vertex(mat, right, bottom, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex(); tessellator.end(); RenderSystem.disableBlend(); diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java index 4d27f16..6492dfa 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java @@ -33,6 +33,7 @@ import net.minecraft.network.chat.Style; public class Tooltips { + private static boolean initialized = false; private static ItemRenderer itemRenderer = null; private static TextureManager textureManager = null; @@ -120,10 +121,11 @@ public class Tooltips } } - public static void init(Minecraft minecraft) + private static void init(Minecraft minecraft) { itemRenderer = minecraft.getItemRenderer(); textureManager = minecraft.getTextureManager(); + initialized = true; } public static void renderItemTooltip(final ItemStack stack, PoseStack mStack, TooltipInfo info, @@ -138,6 +140,12 @@ public class Tooltips Rect2i rect, int screenWidth, int screenHeight, int backgroundColor, int borderColorStart, int borderColorEnd, boolean comparison) { + // Initialize if needed. + if (!initialized) + { + init(Minecraft.getInstance()); + } + if (info.lines.isEmpty()) { return; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0920998..e365eea 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,6 +19,9 @@ "entrypoints": { }, "accessWidener": "iceberg.accesswidener", + "mixins": [ + "iceberg.mixins.json" + ], "depends": { "fabricloader": ">=0.11.3", diff --git a/src/main/resources/iceberg.mixins.json b/src/main/resources/iceberg.mixins.json index 82d2362..25c3dd8 100644 --- a/src/main/resources/iceberg.mixins.json +++ b/src/main/resources/iceberg.mixins.json @@ -2,7 +2,6 @@ "required": true, "package": "com.anthonyhilyard.iceberg.mixin", "compatibilityLevel": "JAVA_8", - "refmap": "iceberg.refmap.json", "mixins": [ "EntityMixin", "PlayerAdvancementsMixin" @@ -16,6 +15,6 @@ "injectors": { "defaultRequire": 1 }, - "minVersion": "0.8.4", + "minVersion": "0.8.2", "target": "@env(DEFAULT)" } |