From 6304cb655be138001192b3ded64db2fb4548dfc1 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Mon, 10 Jul 2023 15:03:47 -0500 Subject: [PATCH] Add GuiGraphics helpers for blitNineSliced and blitRepeating that support specifying a custom texture size (#9641) --- .../client/gui/GuiGraphics.java.patch | 20 +++++++ .../client/extensions/IForgeGuiGraphics.java | 59 +++++++++++++++++++ src/main/resources/forge.exc | 1 + 3 files changed, 80 insertions(+) diff --git a/patches/minecraft/net/minecraft/client/gui/GuiGraphics.java.patch b/patches/minecraft/net/minecraft/client/gui/GuiGraphics.java.patch index 67620ea4d3..9cc6bf9c3d 100644 --- a/patches/minecraft/net/minecraft/client/gui/GuiGraphics.java.patch +++ b/patches/minecraft/net/minecraft/client/gui/GuiGraphics.java.patch @@ -33,6 +33,26 @@ int i = p_282636_.m_272191_(p_281596_, (float)p_281586_, (float)p_282816_, p_281743_, p_282394_, this.f_279612_.m_85850_().m_252922_(), this.f_279627_, Font.DisplayMode.NORMAL, 0, 15728880); this.m_286081_(); return i; +@@ -405,6 +_,10 @@ + } + + public void m_280543_(ResourceLocation p_283059_, int p_283575_, int p_283192_, int p_281790_, int p_283642_, int p_282691_, int p_281912_, int p_281728_, int p_282324_) { ++ blitRepeating(p_283059_, p_283575_, p_283192_, p_281790_, p_283642_, p_282691_, p_281912_, p_281728_, p_282324_, 256, 256); ++ } ++ ++ public void blitRepeating(ResourceLocation p_283059_, int p_283575_, int p_283192_, int p_281790_, int p_283642_, int p_282691_, int p_281912_, int p_281728_, int p_282324_, int textureWidth, int textureHeight) { + int i = p_283575_; + + int j; +@@ -417,7 +_,7 @@ + for(IntIterator intiterator1 = m_280358_(p_283642_, p_282324_); intiterator1.hasNext(); l += i1) { + i1 = intiterator1.nextInt(); + int j1 = (p_282324_ - i1) / 2; +- this.m_280218_(p_283059_, i, l, p_282691_ + k, p_281912_ + j1, j, i1); ++ this.m_280163_(p_283059_, i, l, p_282691_ + k, p_281912_ + j1, j, i1, textureWidth, textureHeight); + } + } + @@ -477,6 +_,7 @@ crashreportcategory.m_128165_("Item Type", () -> { return String.valueOf((Object)p_281675_.m_41720_()); diff --git a/src/main/java/net/minecraftforge/client/extensions/IForgeGuiGraphics.java b/src/main/java/net/minecraftforge/client/extensions/IForgeGuiGraphics.java index 8831e62027..2bf0fc135c 100644 --- a/src/main/java/net/minecraftforge/client/extensions/IForgeGuiGraphics.java +++ b/src/main/java/net/minecraftforge/client/extensions/IForgeGuiGraphics.java @@ -136,4 +136,63 @@ public interface IForgeGuiGraphics self().blit(texture, x, y, boundsWidth, boundsHeight, 0.0f,0.0f, rectWidth, rectHeight, rectWidth, rectHeight); } + + /** + * Version of {@link GuiGraphics#blitNineSliced(ResourceLocation, int, int, int, int, int, int, int, int, int)} that supports specifying the texture's size. + */ + default void blitNineSlicedSized(ResourceLocation texture, int x, int y, int width, int height, int sliceSize, int uWidth, int vHeight, int uOffset, int vOffset, + int textureWidth, int textureHeight) + { + blitNineSlicedSized(texture, x, y, width, height, sliceSize, sliceSize, uWidth, vHeight, uOffset, vOffset, textureWidth, textureHeight); + } + + /** + * Version of {@link GuiGraphics#blitNineSliced(ResourceLocation, int, int, int, int, int, int, int, int, int, int)} that supports specifying the texture's size. + */ + default void blitNineSlicedSized(ResourceLocation texture, int x, int y, int width, int height, int sliceWidth, int sliceHeight, int uWidth, int vHeight, + int uOffset, int vOffset, int textureWidth, int textureHeight) + { + blitNineSlicedSized(texture, x, y, width, height, sliceWidth, sliceHeight, sliceWidth, sliceHeight, uWidth, vHeight, uOffset, vOffset, textureWidth, textureHeight); + } + + /** + * Version of {@link GuiGraphics#blitNineSliced(ResourceLocation, int, int, int, int, int, int, int, int, int, int, int, int)} that supports specifying the texture's size. + */ + default void blitNineSlicedSized(ResourceLocation texture, int x, int y, int width, int height, int cornerWidth, int cornerHeight, int edgeWidth, int edgeHeight, + int uWidth, int vHeight, int uOffset, int vOffset, int textureWidth, int textureHeight) + { + cornerWidth = Math.min(cornerWidth, width / 2); + edgeWidth = Math.min(edgeWidth, width / 2); + cornerHeight = Math.min(cornerHeight, height / 2); + edgeHeight = Math.min(edgeHeight, height / 2); + GuiGraphics self = self(); + if (width == uWidth && height == vHeight) + { + self.blit(texture, x, y, uOffset, vOffset, width, height, textureWidth, textureHeight); + } + else if (height == vHeight) + { + self.blit(texture, x, y, uOffset, vOffset, cornerWidth, height, textureWidth, textureHeight); + self.blitRepeating(texture, x + cornerWidth, y, width - edgeWidth - cornerWidth, height, uOffset + cornerWidth, vOffset, uWidth - edgeWidth - cornerWidth, vHeight, textureWidth, textureHeight); + self.blit(texture, x + width - edgeWidth, y, uOffset + uWidth - edgeWidth, vOffset, edgeWidth, height, textureWidth, textureHeight); + } + else if (width == uWidth) + { + self.blit(texture, x, y, uOffset, vOffset, width, cornerHeight, textureWidth, textureHeight); + self.blitRepeating(texture, x, y + cornerHeight, width, height - edgeHeight - cornerHeight, uOffset, vOffset + cornerHeight, uWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight); + self.blit(texture, x, y + height - edgeHeight, uOffset, vOffset + vHeight - edgeHeight, width, edgeHeight, textureWidth, textureHeight); + } + else + { + self.blit(texture, x, y, uOffset, vOffset, cornerWidth, cornerHeight, textureWidth, textureHeight); + self.blitRepeating(texture, x + cornerWidth, y, width - edgeWidth - cornerWidth, cornerHeight, uOffset + cornerWidth, vOffset, uWidth - edgeWidth - cornerWidth, cornerHeight, textureWidth, textureHeight); + self.blit(texture, x + width - edgeWidth, y, uOffset + uWidth - edgeWidth, vOffset, edgeWidth, cornerHeight, textureWidth, textureHeight); + self.blit(texture, x, y + height - edgeHeight, uOffset, vOffset + vHeight - edgeHeight, cornerWidth, edgeHeight, textureWidth, textureHeight); + self.blitRepeating(texture, x + cornerWidth, y + height - edgeHeight, width - edgeWidth - cornerWidth, edgeHeight, uOffset + cornerWidth, vOffset + vHeight - edgeHeight, uWidth - edgeWidth - cornerWidth, edgeHeight, textureWidth, textureHeight); + self.blit(texture, x + width - edgeWidth, y + height - edgeHeight, uOffset + uWidth - edgeWidth, vOffset + vHeight - edgeHeight, edgeWidth, edgeHeight, textureWidth, textureHeight); + self.blitRepeating(texture, x, y + cornerHeight, cornerWidth, height - edgeHeight - cornerHeight, uOffset, vOffset + cornerHeight, cornerWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight); + self.blitRepeating(texture, x + cornerWidth, y + cornerHeight, width - edgeWidth - cornerWidth, height - edgeHeight - cornerHeight, uOffset + cornerWidth, vOffset + cornerHeight, uWidth - edgeWidth - cornerWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight); + self.blitRepeating(texture, x + width - edgeWidth, y + cornerHeight, cornerWidth, height - edgeHeight - cornerHeight, uOffset + uWidth - edgeWidth, vOffset + cornerHeight, edgeWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight); + } + } } diff --git a/src/main/resources/forge.exc b/src/main/resources/forge.exc index 4061de096d..041be0174e 100644 --- a/src/main/resources/forge.exc +++ b/src/main/resources/forge.exc @@ -1,6 +1,7 @@ com/mojang/blaze3d/vertex/VertexConsumer.putBulkData(Lcom/mojang/blaze3d/vertex/PoseStack$Pose;Lnet/minecraft/client/renderer/block/model/BakedQuad;[FFFFF[IIZ)V=|p_85996_,p_85997_,p_85998_,p_85999_,p_86000_,p_86001_,alpha,p_86002_,p_86003_,p_86004_ net/minecraft/advancements/Advancement$Builder.fromJson(Lcom/google/gson/JsonObject;Lnet/minecraft/advancements/critereon/DeserializationContext;Lnet/minecraftforge/common/crafting/conditions/ICondition$IContext;)Lnet/minecraft/advancements/Advancement$Builder;=|p_138381_,p_138382_,context net/minecraft/client/Options.processOptionsForge(Lnet/minecraft/client/Options$FieldAccess;)V=|p_168428_ +net/minecraft/client/gui/GuiGraphics.blitRepeating(Lnet/minecraft/resources/ResourceLocation;IIIIIIIIII)V=|p_283059_,p_283575_,p_283192_,p_281790_,p_283642_,p_282691_,p_281912_,p_281728_,p_282324_,textureWidth,textureHeight net/minecraft/client/gui/screens/MenuScreens.getScreenFactory(Lnet/minecraft/world/inventory/MenuType;Lnet/minecraft/client/Minecraft;ILnet/minecraft/network/chat/Component;)Ljava/util/Optional;=|p_96202_,p_96203_,p_96204_,p_96205_ net/minecraft/client/gui/screens/inventory/InventoryScreen.renderEntityInInventoryFollowsAngle(Lnet/minecraft/client/gui/GuiGraphics;IIIFFLnet/minecraft/world/entity/LivingEntity;)V=|p_282802_,p_275688_,p_275245_,p_275535_,angleXComponent,angleYComponent,p_275689_ net/minecraft/client/gui/screens/inventory/tooltip/TooltipRenderUtil.renderRectangle(Lnet/minecraft/client/gui/GuiGraphics;IIIIIII)V=|p_281392_,p_282294_,p_283353_,p_282640_,p_281964_,p_283211_,p_282349_,colorTo