diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2023-12-02 09:46:44 -0800 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2023-12-02 09:46:44 -0800 |
commit | 8f249d845ca4e3b00218e4aa71750a478541b524 (patch) | |
tree | 4b65dcb40f8ebd3a4151c8b281c3440813603ba9 /src | |
parent | f37e965d1f2a8d8aa26c9673bc1c1fb732c22ecc (diff) | |
download | Iceberg-8f249d845ca4e3b00218e4aa71750a478541b524.tar.gz Iceberg-8f249d845ca4e3b00218e4aa71750a478541b524.tar.bz2 Iceberg-8f249d845ca4e3b00218e4aa71750a478541b524.zip |
Added support for Sodium 0.5.0.
Diffstat (limited to 'src')
8 files changed, 31 insertions, 30 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/GuiGraphicsMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/GuiGraphicsMixin.java index 30babf4..1c34ed5 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/mixin/GuiGraphicsMixin.java +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/GuiGraphicsMixin.java @@ -45,7 +45,7 @@ public class GuiGraphicsMixin @Final private Minecraft minecraft; - private static ItemStack tooltipStack = ItemStack.EMPTY; + private static ItemStack icebergTooltipStack = ItemStack.EMPTY; private int storedTooltipWidth, storedTooltipHeight; private Vector2ic storedPostPos; @@ -56,13 +56,13 @@ public class GuiGraphicsMixin @Inject(method = "renderTooltip(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;II)V", at = @At(value = "HEAD")) protected void renderTooltipHead(Font font, ItemStack itemStack, int x, int y, CallbackInfo info) { - tooltipStack = itemStack; + icebergTooltipStack = itemStack; } @Inject(method = "renderTooltip(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;II)V", at = @At(value = "TAIL")) protected void renderTooltipTail(Font font, ItemStack itemStack, int x, int y, CallbackInfo info) { - tooltipStack = ItemStack.EMPTY; + icebergTooltipStack = ItemStack.EMPTY; } @Inject(method = "renderTooltip(Lnet/minecraft/client/gui/Font;Ljava/util/List;Ljava/util/Optional;II)V", @@ -78,13 +78,13 @@ public class GuiGraphicsMixin // If the tooltip stack is empty, try to get the stack from the slot under the mouse. // This is needed for the creative inventory screen, which doesn't set the tooltip stack. - if (tooltipStack.isEmpty() && hoveredSlot != null) + if (icebergTooltipStack.isEmpty() && hoveredSlot != null) { - tooltipStack = hoveredSlot.getItem(); + icebergTooltipStack = hoveredSlot.getItem(); } } - List<ClientTooltipComponent> newComponents = Tooltips.gatherTooltipComponents(tooltipStack, textComponents, itemComponent, x, currentScreen.width, currentScreen.height, null, font, -1); + List<ClientTooltipComponent> newComponents = Tooltips.gatherTooltipComponents(icebergTooltipStack, textComponents, itemComponent, x, currentScreen.width, currentScreen.height, null, font, -1); if (newComponents != null && !newComponents.isEmpty()) { components.clear(); @@ -110,9 +110,9 @@ public class GuiGraphicsMixin } else { - if (FabricLoader.getInstance().isModLoaded("andromeda") && tooltipStack != null && !tooltipStack.isEmpty()) + if (FabricLoader.getInstance().isModLoaded("andromeda") && icebergTooltipStack != null && !icebergTooltipStack.isEmpty()) { - List<ClientTooltipComponent> newComponents = Tooltips.gatherTooltipComponents(tooltipStack, Screen.getTooltipFromItem(minecraft, tooltipStack), tooltipStack.getTooltipImage(), x, width, height, null, font, -1); + List<ClientTooltipComponent> newComponents = Tooltips.gatherTooltipComponents(icebergTooltipStack, Screen.getTooltipFromItem(minecraft, icebergTooltipStack), icebergTooltipStack.getTooltipImage(), x, width, height, null, font, -1); if (newComponents != null && !newComponents.isEmpty()) { int oldWidth = 0, oldHeight = 0; @@ -129,9 +129,9 @@ public class GuiGraphicsMixin components.clear(); components.addAll(newComponents); - Rect2i newRect = Tooltips.calculateRect(tooltipStack, self, positioner, components, x, y, width, height, width, font, 0, true); + Rect2i newRect = Tooltips.calculateRect(icebergTooltipStack, self, positioner, components, x, y, width, height, width, font, 0, true); - if (tooltipStack == minecraft.player.getMainHandItem()) + if (minecraft.player != null && icebergTooltipStack == minecraft.player.getMainHandItem()) { PoseStack poseStack = RenderSystem.getModelViewStack(); xChange = (oldWidth - newRect.getWidth()) / 2; @@ -149,7 +149,7 @@ public class GuiGraphicsMixin PreExtResult eventResult = null; InteractionResult result = InteractionResult.PASS; - eventResult = RenderTooltipEvents.PREEXT.invoker().onPre(tooltipStack, self, x, y, width, height, font, components, positioner, false, 0); + eventResult = RenderTooltipEvents.PREEXT.invoker().onPre(icebergTooltipStack, self, x, y, width, height, font, components, positioner, false, 0); result = eventResult.result(); if (result != InteractionResult.PASS) @@ -178,7 +178,7 @@ public class GuiGraphicsMixin if (containerStack.isEmpty()) { - containerStack = tooltipStack; + containerStack = icebergTooltipStack; } if (!containerStack.isEmpty()) @@ -235,7 +235,7 @@ public class GuiGraphicsMixin if (containerStack.isEmpty()) { - containerStack = tooltipStack; + containerStack = icebergTooltipStack; } if (!containerStack.isEmpty() && !components.isEmpty()) @@ -243,14 +243,14 @@ public class GuiGraphicsMixin RenderTooltipEvents.POSTEXT.invoker().onPost(containerStack, self, storedPostPos.x(), storedPostPos.y(), font, storedTooltipWidth, storedTooltipHeight, components, false, 0); } - if (FabricLoader.getInstance().isModLoaded("andromeda") && tooltipStack == minecraft.player.getMainHandItem()) + if (FabricLoader.getInstance().isModLoaded("andromeda") && minecraft.player != null && icebergTooltipStack == minecraft.player.getMainHandItem()) { PoseStack poseStack = RenderSystem.getModelViewStack(); poseStack.translate(-xChange, -yChange, 0); RenderSystem.applyModelViewMatrix(); } - tooltipStack = ItemStack.EMPTY; + icebergTooltipStack = ItemStack.EMPTY; xChange = 0; yChange = 0; } diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java index 211903a..da12fc3 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java @@ -28,7 +28,7 @@ public class ScreenMixin { try { - Field tooltipStackField = GuiGraphics.class.getDeclaredField("tooltipStack"); + Field tooltipStackField = GuiGraphics.class.getDeclaredField("icebergTooltipStack"); tooltipStackField.setAccessible(true); tooltipStackField.set(null, itemStack); } diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java index 4eaab58..b5e0cf1 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java +++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java @@ -28,8 +28,8 @@ public class CheckedBufferSource implements MultiBufferSource { try { - // If Sodium 0.4.10 is installed, use the Sodium implementation. - useSodiumVersion = FabricLoader.getInstance().isModLoaded("sodium") && VersionPredicate.parse("0.4.10").test(FabricLoader.getInstance().getModContainer("sodium").get().getMetadata().getVersion()); + // If Sodium 0.5.0+ is installed, use the Sodium implementation. + useSodiumVersion = FabricLoader.getInstance().isModLoaded("sodium") && VersionPredicate.parse(">=0.5.0").test(FabricLoader.getInstance().getModContainer("sodium").get().getMetadata().getVersion()); } catch (Exception e) { diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSourceSodium.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSourceSodium.java index 2a37254..ce8d372 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSourceSodium.java +++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSourceSodium.java @@ -4,11 +4,12 @@ import org.lwjgl.system.MemoryStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; +import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; -import me.jellysquid.mods.sodium.client.render.vertex.VertexBufferWriter; -import me.jellysquid.mods.sodium.client.render.vertex.VertexFormatDescription; + public final class CheckedBufferSourceSodium extends CheckedBufferSource { diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollector.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollector.java index 0c6b9c9..ae7901a 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollector.java +++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollector.java @@ -34,8 +34,8 @@ public class VertexCollector implements MultiBufferSource { try { - // If Sodium 0.4.10 is installed, use the Sodium implementation. - useSodiumVersion = FabricLoader.getInstance().isModLoaded("sodium") && VersionPredicate.parse("0.4.10").test(FabricLoader.getInstance().getModContainer("sodium").get().getMetadata().getVersion()); + // If Sodium 0.5.0+ is installed, use the Sodium implementation. + useSodiumVersion = FabricLoader.getInstance().isModLoaded("sodium") && VersionPredicate.parse(">=0.5.0").test(FabricLoader.getInstance().getModContainer("sodium").get().getMetadata().getVersion()); } catch (Exception e) { diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollectorSodium.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollectorSodium.java index ed0fb7c..41d23f9 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollectorSodium.java +++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollectorSodium.java @@ -6,10 +6,10 @@ import org.lwjgl.system.MemoryStack; import com.anthonyhilyard.iceberg.util.UnsafeUtil; import com.mojang.blaze3d.vertex.VertexConsumer; +import net.caffeinemc.mods.sodium.api.vertex.attributes.CommonVertexAttribute; +import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription; import net.minecraft.client.renderer.RenderType; -import me.jellysquid.mods.sodium.client.render.vertex.VertexFormatDescription; -import me.jellysquid.mods.sodium.client.render.vertex.transform.CommonVertexElement; public class VertexCollectorSodium extends VertexCollector { @@ -79,12 +79,12 @@ public class VertexCollectorSodium extends VertexCollector for (int i = 0; i < count; i++) { // Get the vertex position. - float x = UnsafeUtil.readFloat(pointer + i * format.stride + format.getOffset(CommonVertexElement.POSITION)); - float y = UnsafeUtil.readFloat(pointer + i * format.stride + format.getOffset(CommonVertexElement.POSITION) + 4); - float z = UnsafeUtil.readFloat(pointer + i * format.stride + format.getOffset(CommonVertexElement.POSITION) + 8); + float x = UnsafeUtil.readFloat(pointer + i * format.stride() + format.getElementOffset(CommonVertexAttribute.POSITION)); + float y = UnsafeUtil.readFloat(pointer + i * format.stride() + format.getElementOffset(CommonVertexAttribute.POSITION) + 4); + float z = UnsafeUtil.readFloat(pointer + i * format.stride() + format.getElementOffset(CommonVertexAttribute.POSITION) + 8); // Get the vertex alpha. - int a = UnsafeUtil.readByte(pointer + i * format.stride + format.getOffset(CommonVertexElement.COLOR) + 3) & 0xFF; + int a = UnsafeUtil.readByte(pointer + i * format.stride() + format.getElementOffset(CommonVertexAttribute.COLOR) + 3) & 0xFF; // Add the vertex to the list if it's opaque. if (a >= 25) diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexConsumerSodium.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexConsumerSodium.java index c02ef30..7322576 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexConsumerSodium.java +++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexConsumerSodium.java @@ -2,7 +2,7 @@ package com.anthonyhilyard.iceberg.renderer; import com.mojang.blaze3d.vertex.VertexConsumer; -import me.jellysquid.mods.sodium.client.render.vertex.VertexBufferWriter; +import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; public interface VertexConsumerSodium extends VertexConsumer, VertexBufferWriter { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index da1e3ce..c74cf27 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -34,7 +34,7 @@ "java": ">=17" }, "suggests": { - "sodium": "0.4.10" + "sodium": ">=0.5.0" }, "custom": { "modupdater": { |