diff options
Diffstat (limited to 'src')
5 files changed, 49 insertions, 17 deletions
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)" } |