From 133788de0b8539a97dc12c59f441e4e562e59b73 Mon Sep 17 00:00:00 2001 From: spiralhalo Date: Thu, 18 May 2023 17:55:29 +0700 Subject: [PATCH 1/4] Update to 1.20-pre2 --- build.gradle | 2 +- gradle.properties | 12 ++--- gradle/wrapper/gradle-wrapper.properties | 2 +- .../mixin/CartographyTableScreenTabAdder.java | 8 ++-- .../mixin/LoomScreenTabAdder.java | 8 ++-- .../mixin/StonecutterScreenTabAdder.java | 8 ++-- .../mixin/VanillaScreenTabAdder.java | 15 +++---- .../mixin/accessor/ScreenAccessor.java | 3 -- .../tabs/provider/BlockTabProvider.java | 2 +- .../tabs/provider/ChestTabProvider.java | 2 +- .../tabs/provider/EnderChestTabProvider.java | 2 +- .../tabs/provider/EntityTabProvider.java | 4 +- .../tabs/provider/LecternTabProvider.java | 4 +- .../tabs/provider/ShulkerBoxTabProvider.java | 6 +-- .../provider/SimpleEntityTabProvider.java | 4 +- .../tabs/render/TabRenderer.java | 44 +++++++++---------- .../kqp/inventorytabs/tabs/tab/ChestTab.java | 18 ++++---- .../inventorytabs/tabs/tab/ShulkerBoxTab.java | 6 +-- .../tabs/tab/SimpleBlockTab.java | 6 +-- .../tabs/tab/SimpleEntityTab.java | 16 +++---- .../com/kqp/inventorytabs/tabs/tab/Tab.java | 16 +++---- .../com/kqp/inventorytabs/util/BlockUtil.java | 2 +- src/main/resources/fabric.mod.json | 4 +- 23 files changed, 94 insertions(+), 100 deletions(-) diff --git a/build.gradle b/build.gradle index de06df7..9d90e78 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.1-SNAPSHOT' + id 'fabric-loom' version '1.2.7' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 02456f1..36840cd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/versions.html - minecraft_version=1.19.4 - yarn_mappings=1.19.4+build.1 + minecraft_version=1.20-pre2 + yarn_mappings=1.20-pre2+build.1 loader_version=0.14.19 # Mod Properties - mod_version = 0.9.0-beta-1.19.4 + mod_version = 0.9.0-beta-1.20 maven_group = com.kqp archives_base_name = inventorytabs # Dependencies - fabric_version=0.77.0+1.19.4 - clothconfig_version=10.0.96 - modmenu_version=6.1.0-rc.4 + fabric_version=0.81.2+1.20 + clothconfig_version=11.0.97 + modmenu_version=6.2.2 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 070cb70..59bc51a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/kqp/inventorytabs/mixin/CartographyTableScreenTabAdder.java b/src/main/java/com/kqp/inventorytabs/mixin/CartographyTableScreenTabAdder.java index c17bc22..90991c6 100644 --- a/src/main/java/com/kqp/inventorytabs/mixin/CartographyTableScreenTabAdder.java +++ b/src/main/java/com/kqp/inventorytabs/mixin/CartographyTableScreenTabAdder.java @@ -11,18 +11,18 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.CartographyTableScreen; import net.minecraft.client.util.math.MatrixStack; @Environment(EnvType.CLIENT) @Mixin(CartographyTableScreen.class) public class CartographyTableScreenTabAdder { - @Inject(method = "drawBackground", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/ingame/CartographyTableScreen;renderBackground(Lnet/minecraft/client/util/math/MatrixStack;)V")) - protected void drawBackgroundTabs(MatrixStack matrices, float delta, int mouseX, int mouseY, - CallbackInfo callbackInfo) { + @Inject(method = "drawBackground", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/ingame/CartographyTableScreen;renderBackground(Lnet/minecraft/client/gui/DrawContext;)V")) + protected void drawBackgroundTabs(DrawContext context, float delta, int mouseX, int mouseY, CallbackInfo ci) { MinecraftClient client = MinecraftClient.getInstance(); TabManager tabManager = ((TabManagerContainer) client).getTabManager(); - tabManager.tabRenderer.renderBackground(matrices); + tabManager.tabRenderer.renderBackground(context); } } diff --git a/src/main/java/com/kqp/inventorytabs/mixin/LoomScreenTabAdder.java b/src/main/java/com/kqp/inventorytabs/mixin/LoomScreenTabAdder.java index b75577b..0c33600 100644 --- a/src/main/java/com/kqp/inventorytabs/mixin/LoomScreenTabAdder.java +++ b/src/main/java/com/kqp/inventorytabs/mixin/LoomScreenTabAdder.java @@ -11,18 +11,18 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.LoomScreen; import net.minecraft.client.util.math.MatrixStack; @Environment(EnvType.CLIENT) @Mixin(LoomScreen.class) public class LoomScreenTabAdder { - @Inject(method = "drawBackground", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/ingame/LoomScreen;renderBackground(Lnet/minecraft/client/util/math/MatrixStack;)V")) - protected void drawBackgroundTabs(MatrixStack matrices, float delta, int mouseX, int mouseY, - CallbackInfo callbackInfo) { + @Inject(method = "drawBackground", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/ingame/LoomScreen;renderBackground(Lnet/minecraft/client/gui/DrawContext;)V")) + protected void drawBackgroundTabs(DrawContext context, float delta, int mouseX, int mouseY, CallbackInfo ci) { MinecraftClient client = MinecraftClient.getInstance(); TabManager tabManager = ((TabManagerContainer) client).getTabManager(); - tabManager.tabRenderer.renderBackground(matrices); + tabManager.tabRenderer.renderBackground(context); } } diff --git a/src/main/java/com/kqp/inventorytabs/mixin/StonecutterScreenTabAdder.java b/src/main/java/com/kqp/inventorytabs/mixin/StonecutterScreenTabAdder.java index 5b93942..b81bfbe 100644 --- a/src/main/java/com/kqp/inventorytabs/mixin/StonecutterScreenTabAdder.java +++ b/src/main/java/com/kqp/inventorytabs/mixin/StonecutterScreenTabAdder.java @@ -11,18 +11,18 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.StonecutterScreen; import net.minecraft.client.util.math.MatrixStack; @Environment(EnvType.CLIENT) @Mixin(StonecutterScreen.class) public class StonecutterScreenTabAdder { - @Inject(method = "drawBackground", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/ingame/StonecutterScreen;renderBackground(Lnet/minecraft/client/util/math/MatrixStack;)V")) - protected void drawBackgroundTabs(MatrixStack matrices, float delta, int mouseX, int mouseY, - CallbackInfo callbackInfo) { + @Inject(method = "drawBackground", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/client/gui/screen/ingame/StonecutterScreen;renderBackground(Lnet/minecraft/client/gui/DrawContext;)V")) + protected void drawBackgroundTabs(DrawContext context, float delta, int mouseX, int mouseY, CallbackInfo ci) { MinecraftClient client = MinecraftClient.getInstance(); TabManager tabManager = ((TabManagerContainer) client).getTabManager(); - tabManager.tabRenderer.renderBackground(matrices); + tabManager.tabRenderer.renderBackground(context); } } diff --git a/src/main/java/com/kqp/inventorytabs/mixin/VanillaScreenTabAdder.java b/src/main/java/com/kqp/inventorytabs/mixin/VanillaScreenTabAdder.java index a43c79f..002d63f 100644 --- a/src/main/java/com/kqp/inventorytabs/mixin/VanillaScreenTabAdder.java +++ b/src/main/java/com/kqp/inventorytabs/mixin/VanillaScreenTabAdder.java @@ -13,6 +13,7 @@ import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.*; import org.spongepowered.asm.mixin.Mixin; @@ -74,7 +75,7 @@ private void initTabRenderer(CallbackInfo callbackInfo) { matchingBlockPositions.add(blockPos); // For double chests - World world = client.player.world; + World world = client.player.getWorld(); if (world.getBlockState(blockPos).getBlock() instanceof ChestBlock) { if (ChestUtil.isDouble(world, blockPos)) { matchingBlockPositions.add(ChestUtil.getOtherChestBlockPos(world, blockPos)); @@ -101,27 +102,25 @@ private void initTabRenderer(CallbackInfo callbackInfo) { } @Inject(method = "render", at = @At("HEAD")) - protected void drawBackgroundTabs(MatrixStack matrices, int mouseX, int mouseY, float delta, - CallbackInfo callbackInfo) { + protected void drawBackgroundTabs(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { if (InventoryTabsClient.screenSupported(this)) { if (!screenDoesDumbBlock()) { MinecraftClient client = MinecraftClient.getInstance(); TabManager tabManager = ((TabManagerContainer) client).getTabManager(); - tabManager.tabRenderer.renderBackground(matrices); + tabManager.tabRenderer.renderBackground(context); } } } @Inject(method = "render", at = @At("TAIL")) - protected void drawForegroundTabs(MatrixStack matrices, int mouseX, int mouseY, float delta, - CallbackInfo callbackInfo) { + protected void drawForegroundTabs(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { if (InventoryTabsClient.screenSupported(this)) { MinecraftClient client = MinecraftClient.getInstance(); TabManager tabManager = ((TabManagerContainer) client).getTabManager(); - tabManager.tabRenderer.renderForeground(matrices, mouseX, mouseY); - tabManager.tabRenderer.renderHoverTooltips(matrices, mouseX, mouseY); + tabManager.tabRenderer.renderForeground(context, mouseX, mouseY); + tabManager.tabRenderer.renderHoverTooltips(context, mouseX, mouseY); } } diff --git a/src/main/java/com/kqp/inventorytabs/mixin/accessor/ScreenAccessor.java b/src/main/java/com/kqp/inventorytabs/mixin/accessor/ScreenAccessor.java index a9785af..f9b249b 100644 --- a/src/main/java/com/kqp/inventorytabs/mixin/accessor/ScreenAccessor.java +++ b/src/main/java/com/kqp/inventorytabs/mixin/accessor/ScreenAccessor.java @@ -12,9 +12,6 @@ @Environment(EnvType.CLIENT) @Mixin(Screen.class) public interface ScreenAccessor { - @Accessor - ItemRenderer getItemRenderer(); - @Accessor TextRenderer getTextRenderer(); } diff --git a/src/main/java/com/kqp/inventorytabs/tabs/provider/BlockTabProvider.java b/src/main/java/com/kqp/inventorytabs/tabs/provider/BlockTabProvider.java index 79c0ba5..e2a5cd7 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/provider/BlockTabProvider.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/provider/BlockTabProvider.java @@ -20,7 +20,7 @@ public abstract class BlockTabProvider implements TabProvider { @Override public void addAvailableTabs(ClientPlayerEntity player, List tabs) { - World world = player.world; + World world = player.getWorld(); // TODO: make this better and check line of sight for (int x = -SEARCH_DISTANCE; x <= SEARCH_DISTANCE; x++) { diff --git a/src/main/java/com/kqp/inventorytabs/tabs/provider/ChestTabProvider.java b/src/main/java/com/kqp/inventorytabs/tabs/provider/ChestTabProvider.java index d021dfc..f94e7fa 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/provider/ChestTabProvider.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/provider/ChestTabProvider.java @@ -32,7 +32,7 @@ public void addAvailableTabs(ClientPlayerEntity player, List tabs) { List chestTabs = tabs.stream().filter(tab -> tab instanceof ChestTab).map(tab -> (ChestTab) tab) .filter(tab -> chestBlocks.contains(tab.blockId)).toList(); - World world = player.world; + World world = player.getWorld(); // Add any chests that are blocked chestTabs.stream().filter(tab -> ChestBlock.isChestBlocked(world, tab.blockPos)).forEach(tabsToRemove::add); diff --git a/src/main/java/com/kqp/inventorytabs/tabs/provider/EnderChestTabProvider.java b/src/main/java/com/kqp/inventorytabs/tabs/provider/EnderChestTabProvider.java index f9e8250..c311ba5 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/provider/EnderChestTabProvider.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/provider/EnderChestTabProvider.java @@ -29,7 +29,7 @@ public void addAvailableTabs(ClientPlayerEntity player, List tabs) { List chestTabs = tabs.stream().filter(tab -> tab instanceof ChestTab).map(tab -> (ChestTab) tab) .filter(tab -> tab.blockId == Registries.BLOCK.getId(Blocks.ENDER_CHEST)).toList(); - World world = player.world; + World world = player.getWorld(); // Add any chests that are blocked chestTabs.stream().filter(tab -> ChestBlock.isChestBlocked(world, tab.blockPos)).forEach(tabsToRemove::add); diff --git a/src/main/java/com/kqp/inventorytabs/tabs/provider/EntityTabProvider.java b/src/main/java/com/kqp/inventorytabs/tabs/provider/EntityTabProvider.java index e6d6950..e5c3946 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/provider/EntityTabProvider.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/provider/EntityTabProvider.java @@ -17,7 +17,7 @@ public abstract class EntityTabProvider implements TabProvider { public static final int SEARCH_DISTANCE = 5; @Override public void addAvailableTabs(ClientPlayerEntity player, List tabs) { - World world = player.world; + World world = player.getWorld(); List entityList = world.getNonSpectatingEntities(Entity.class, new Box(player.getBlockPos().getX()-SEARCH_DISTANCE, player.getBlockPos().getY()-SEARCH_DISTANCE, player.getBlockPos().getZ()-SEARCH_DISTANCE, player.getBlockPos().getX()+SEARCH_DISTANCE, player.getBlockPos().getY()+SEARCH_DISTANCE, player.getBlockPos().getZ()+SEARCH_DISTANCE)); for (Entity entity : entityList) { @@ -60,4 +60,4 @@ public void addAvailableTabs(ClientPlayerEntity player, List tabs) { * @return */ public abstract Tab createTab(Entity entity); -} \ No newline at end of file +} diff --git a/src/main/java/com/kqp/inventorytabs/tabs/provider/LecternTabProvider.java b/src/main/java/com/kqp/inventorytabs/tabs/provider/LecternTabProvider.java index 643e01f..cf6445b 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/provider/LecternTabProvider.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/provider/LecternTabProvider.java @@ -27,10 +27,10 @@ public void addAvailableTabs(ClientPlayerEntity player, List tabs) { List lecternTabs = tabs.stream().filter(tab -> tab instanceof SimpleBlockTab).map(tab -> (SimpleBlockTab) tab) .filter(tab -> tab.blockId == Registries.BLOCK.getId(Blocks.LECTERN)).toList(); lecternTabs.stream().filter(tab -> { - BlockEntity blockEntity = player.world.getBlockEntity(tab.blockPos); + BlockEntity blockEntity = player.getWorld().getBlockEntity(tab.blockPos); if (blockEntity instanceof LecternBlockEntity) { - BlockState blockState = player.world.getBlockState(tab.blockPos); + BlockState blockState = player.getWorld().getBlockState(tab.blockPos); return !blockState.get(HAS_BOOK); } diff --git a/src/main/java/com/kqp/inventorytabs/tabs/provider/ShulkerBoxTabProvider.java b/src/main/java/com/kqp/inventorytabs/tabs/provider/ShulkerBoxTabProvider.java index 5559a59..2415fb4 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/provider/ShulkerBoxTabProvider.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/provider/ShulkerBoxTabProvider.java @@ -34,12 +34,12 @@ public void addAvailableTabs(ClientPlayerEntity player, List tabs) { // Add any chests that are blocked shulkerTabs.stream().filter(tab -> { - BlockEntity blockEntity = player.world.getBlockEntity(tab.blockPos); + BlockEntity blockEntity = player.getWorld().getBlockEntity(tab.blockPos); if (blockEntity instanceof ShulkerBoxBlockEntity) { - BlockState blockState = player.world.getBlockState(tab.blockPos); + BlockState blockState = player.getWorld().getBlockState(tab.blockPos); - return !ShulkerBoxBlockInvoker.invokeCanOpen(blockState, player.world, tab.blockPos, + return !ShulkerBoxBlockInvoker.invokeCanOpen(blockState, player.getWorld(), tab.blockPos, (ShulkerBoxBlockEntity) blockEntity); } diff --git a/src/main/java/com/kqp/inventorytabs/tabs/provider/SimpleEntityTabProvider.java b/src/main/java/com/kqp/inventorytabs/tabs/provider/SimpleEntityTabProvider.java index abe9eb5..d785efa 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/provider/SimpleEntityTabProvider.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/provider/SimpleEntityTabProvider.java @@ -23,7 +23,7 @@ public void addAvailableTabs(ClientPlayerEntity player, List tabs) { Set tabsToRemove = new HashSet<>(); List entityTabs = tabs.stream().filter(tab -> tab instanceof SimpleEntityTab).map(tab -> (SimpleEntityTab) tab) .filter(tab -> entities.contains(tab.entityId)).toList(); - World world = player.world; + World world = player.getWorld(); } @Override @@ -39,4 +39,4 @@ public void addEntity(Identifier entityId) { public Tab createTab(Entity entity) { return new SimpleEntityTab(entity); } -} \ No newline at end of file +} diff --git a/src/main/java/com/kqp/inventorytabs/tabs/render/TabRenderer.java b/src/main/java/com/kqp/inventorytabs/tabs/render/TabRenderer.java index cebf248..9766e6f 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/render/TabRenderer.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/render/TabRenderer.java @@ -4,6 +4,7 @@ import com.kqp.inventorytabs.init.InventoryTabs; import com.kqp.inventorytabs.mixin.accessor.HandledScreenAccessor; +import com.kqp.inventorytabs.mixin.accessor.ScreenAccessor; import com.kqp.inventorytabs.tabs.TabManager; import com.kqp.inventorytabs.tabs.tab.Tab; import com.mojang.blaze3d.systems.RenderSystem; @@ -12,6 +13,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; @@ -41,9 +43,7 @@ public TabRenderer(TabManager tabManager) { this.tabManager = tabManager; } - public void renderBackground(MatrixStack matrices) { - matrices.push(); - + public void renderBackground(DrawContext context) { tabRenderInfos = getTabRenderInfos(); for (int i = 0; i < tabRenderInfos.length; i++) { @@ -51,14 +51,13 @@ public void renderBackground(MatrixStack matrices) { if (tabRenderInfo != null) { if (tabRenderInfo.tabReference != tabManager.currentTab) { - renderTab(matrices, tabRenderInfo); + renderTab(context, tabRenderInfo); } } } - matrices.pop(); } - public void renderForeground(MatrixStack matrices, double mouseX, double mouseY) { + public void renderForeground(DrawContext context, double mouseX, double mouseY) { RenderSystem.setShaderTexture(0, TABS_TEXTURE); for (int i = 0; i < tabRenderInfos.length; i++) { @@ -66,21 +65,19 @@ public void renderForeground(MatrixStack matrices, double mouseX, double mouseY) if (tabRenderInfo != null) { if (tabRenderInfo.tabReference == tabManager.currentTab) { - renderTab(matrices, tabRenderInfo); + renderTab(context, tabRenderInfo); } } } - drawButtons(matrices, mouseX, mouseY); + drawButtons(context, mouseX, mouseY); - drawPageText(matrices); + drawPageText(context); } - private void drawButtons(MatrixStack matrices, double mouseX, double mouseY) { + private void drawButtons(DrawContext context, double mouseX, double mouseY) { HandledScreen currentScreen = tabManager.getCurrentScreen(); - RenderSystem.setShaderTexture(0, BUTTONS_TEXTURE); - int width = ((HandledScreenAccessor) currentScreen).getBackgroundWidth(); int height = ((HandledScreenAccessor) currentScreen).getBackgroundHeight(); int oX = (currentScreen.width - width) / 2; @@ -95,7 +92,7 @@ private void drawButtons(MatrixStack matrices, double mouseX, double mouseY) { int u = 0; u += tabManager.canGoBackAPage() && hovered ? BUTTON_WIDTH * 2 : 0; int v = tabManager.canGoBackAPage() ? 0 : 13; - currentScreen.drawTexture(matrices, x, y, u, v, BUTTON_WIDTH, BUTTON_HEIGHT); + context.drawTexture(BUTTONS_TEXTURE, x, y, u, v, BUTTON_WIDTH, BUTTON_HEIGHT); // Drawing forward button x = oX + width + 4; @@ -106,10 +103,10 @@ private void drawButtons(MatrixStack matrices, double mouseX, double mouseY) { u = 15; u += tabManager.canGoForwardAPage() && hovered ? BUTTON_WIDTH * 2 : 0; v = tabManager.canGoForwardAPage() ? 0 : 13; - currentScreen.drawTexture(matrices, x, y, u, v, BUTTON_WIDTH, BUTTON_HEIGHT); + context.drawTexture(BUTTONS_TEXTURE, x, y, u, v, BUTTON_WIDTH, BUTTON_HEIGHT); } - private void drawPageText(MatrixStack matrices) { + private void drawPageText(DrawContext context) { if (tabManager.getMaxPages() > 1 && pageTextRefreshTime > 0) { // RenderSystem.pushMatrix(); // TODO: Figure out rendering @@ -138,23 +135,25 @@ private void drawPageText(MatrixStack matrices) { int x = (oX - textRenderer.getWidth(text)) / 2; int y = oY - 34; - MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color); + context.drawText(MinecraftClient.getInstance().textRenderer, text, x, y, color, false); // RenderSystem.popMatrix(); } } - private void renderTab(MatrixStack matrices, TabRenderInfo tabRenderInfo) { + private void renderTab(DrawContext context, TabRenderInfo tabRenderInfo) { HandledScreen currentScreen = tabManager.getCurrentScreen(); - RenderSystem.setShaderTexture(0, TABS_TEXTURE); - currentScreen.drawTexture(matrices, tabRenderInfo.x, tabRenderInfo.y, tabRenderInfo.texU, tabRenderInfo.texV, + context.drawTexture(TABS_TEXTURE, tabRenderInfo.x, tabRenderInfo.y, tabRenderInfo.texU, tabRenderInfo.texV, tabRenderInfo.texW, tabRenderInfo.texH); - tabRenderInfo.tabReference.renderTabIcon(matrices, tabRenderInfo, currentScreen); + tabRenderInfo.tabReference.renderTabIcon(context, tabRenderInfo, currentScreen); } - public void renderHoverTooltips(MatrixStack matrices, double mouseX, double mouseY) { + public void renderHoverTooltips(DrawContext context, double mouseX, double mouseY) { + HandledScreen currentScreen = tabManager.getCurrentScreen(); + TextRenderer textRenderer = ((ScreenAccessor) currentScreen).getTextRenderer(); + for (int i = 0; i < tabRenderInfos.length; i++) { TabRenderInfo tabRenderInfo = tabRenderInfos[i]; @@ -162,8 +161,7 @@ public void renderHoverTooltips(MatrixStack matrices, double mouseX, double mous Rectangle itemRec = new Rectangle(tabRenderInfo.itemX, tabRenderInfo.itemY, 16, 16); if (itemRec.contains(mouseX, mouseY)) { - tabManager.getCurrentScreen().renderTooltip(matrices, tabRenderInfo.tabReference.getHoverText(), - (int) mouseX, (int) mouseY); + context.drawTooltip(textRenderer, tabRenderInfo.tabReference.getHoverText(), (int) mouseX, (int) mouseY); } } } diff --git a/src/main/java/com/kqp/inventorytabs/tabs/tab/ChestTab.java b/src/main/java/com/kqp/inventorytabs/tabs/tab/ChestTab.java index 5cd32be..86f7bcc 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/tab/ChestTab.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/tab/ChestTab.java @@ -6,6 +6,7 @@ import net.minecraft.block.ChestBlock; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.item.ItemRenderer; @@ -39,7 +40,7 @@ public ChestTab(Identifier blockId, BlockPos blockPos) { public boolean shouldBeRemoved() { ClientPlayerEntity player = MinecraftClient.getInstance().player; - if (ChestBlock.isChestBlocked(player.world, blockPos)) { + if (ChestBlock.isChestBlocked(player.getWorld(), blockPos)) { return true; } @@ -55,19 +56,18 @@ public Text getHoverText() { } @Override - public void renderTabIcon(MatrixStack matrices, TabRenderInfo tabRenderInfo, HandledScreen currentScreen) { + public void renderTabIcon(DrawContext context, TabRenderInfo tabRenderInfo, HandledScreen currentScreen) { ItemStack itemStack = getItemFrame(); - ItemRenderer itemRenderer = ((ScreenAccessor) currentScreen).getItemRenderer(); TextRenderer textRenderer = ((ScreenAccessor) currentScreen).getTextRenderer(); - matrices.push(); - matrices.translate(0, 0, 100.0F); - itemRenderer.renderInGuiWithOverrides(matrices, itemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); - itemRenderer.renderGuiItemOverlay(matrices, textRenderer, itemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); - matrices.pop(); + context.getMatrices().push(); + context.getMatrices().translate(0, 0, 100.0F); + context.drawItem(itemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); + context.drawItemInSlot(textRenderer, itemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); + context.getMatrices().pop(); } public ItemStack getItemFrame() { - World world = MinecraftClient.getInstance().player.world; + World world = MinecraftClient.getInstance().player.getWorld(); itemStack = new ItemStack(world.getBlockState(blockPos).getBlock()); BlockPos doubleChestPos = ChestUtil.isDouble(world, blockPos) ? getOtherChestBlockPos(world, blockPos) : blockPos; Box box = new Box(blockPos, doubleChestPos); diff --git a/src/main/java/com/kqp/inventorytabs/tabs/tab/ShulkerBoxTab.java b/src/main/java/com/kqp/inventorytabs/tabs/tab/ShulkerBoxTab.java index f79f139..1b51b69 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/tab/ShulkerBoxTab.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/tab/ShulkerBoxTab.java @@ -22,12 +22,12 @@ public ShulkerBoxTab(Identifier blockId, BlockPos blockPos) { public boolean shouldBeRemoved() { ClientPlayerEntity player = MinecraftClient.getInstance().player; - BlockEntity blockEntity = player.world.getBlockEntity(blockPos); + BlockEntity blockEntity = player.getWorld().getBlockEntity(blockPos); if (blockEntity instanceof ShulkerBoxBlockEntity) { - BlockState blockState = player.world.getBlockState(blockPos); + BlockState blockState = player.getWorld().getBlockState(blockPos); - return !ShulkerBoxBlockInvoker.invokeCanOpen(blockState, player.world, blockPos, + return !ShulkerBoxBlockInvoker.invokeCanOpen(blockState, player.getWorld(), blockPos, (ShulkerBoxBlockEntity) blockEntity); } diff --git a/src/main/java/com/kqp/inventorytabs/tabs/tab/SimpleBlockTab.java b/src/main/java/com/kqp/inventorytabs/tabs/tab/SimpleBlockTab.java index a34fd02..e4f06f5 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/tab/SimpleBlockTab.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/tab/SimpleBlockTab.java @@ -30,7 +30,7 @@ public class SimpleBlockTab extends Tab { public final BlockPos blockPos; public SimpleBlockTab(Identifier blockId, BlockPos blockPos) { - super(new ItemStack(MinecraftClient.getInstance().player.world.getBlockState(blockPos).getBlock())); + super(new ItemStack(MinecraftClient.getInstance().player.getWorld().getBlockState(blockPos).getBlock())); this.blockId = blockId; this.blockPos = blockPos; } @@ -61,7 +61,7 @@ public void open() { public boolean shouldBeRemoved() { ClientPlayerEntity player = MinecraftClient.getInstance().player; - if (!Registries.BLOCK.getId(player.world.getBlockState(blockPos).getBlock()).equals(blockId)) { + if (!Registries.BLOCK.getId(player.getWorld().getBlockState(blockPos).getBlock()).equals(blockId)) { return true; } @@ -81,7 +81,7 @@ public boolean shouldBeRemoved() { @Override public Text getHoverText() { - World world = MinecraftClient.getInstance().player.world; + World world = MinecraftClient.getInstance().player.getWorld(); BlockEntity blockEntity = world.getBlockEntity(blockPos); diff --git a/src/main/java/com/kqp/inventorytabs/tabs/tab/SimpleEntityTab.java b/src/main/java/com/kqp/inventorytabs/tabs/tab/SimpleEntityTab.java index 5c83f94..b3c288e 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/tab/SimpleEntityTab.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/tab/SimpleEntityTab.java @@ -4,6 +4,7 @@ import com.kqp.inventorytabs.tabs.render.TabRenderInfo; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.item.ItemRenderer; @@ -49,15 +50,14 @@ public Text getHoverText() { } @Override - public void renderTabIcon(MatrixStack matrices, TabRenderInfo tabRenderInfo, HandledScreen currentScreen) { + public void renderTabIcon(DrawContext context, TabRenderInfo tabRenderInfo, HandledScreen currentScreen) { ItemStack itemStack = getItemStack(); - ItemRenderer itemRenderer = ((ScreenAccessor) currentScreen).getItemRenderer(); TextRenderer textRenderer = ((ScreenAccessor) currentScreen).getTextRenderer(); - matrices.push(); - matrices.translate(0, 0, 100.0F); - itemRenderer.renderInGuiWithOverrides(matrices, itemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); - itemRenderer.renderGuiItemOverlay(matrices, textRenderer, itemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); - matrices.pop(); + context.getMatrices().push(); + context.getMatrices().translate(0, 0, 100.0F); + context.drawItem(itemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); + context.drawItemInSlot(textRenderer, itemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); + context.getMatrices().pop(); } @Override @@ -80,4 +80,4 @@ public int hashCode() { public ItemStack getItemStack() { return entity.getPickBlockStack() != null ? entity.getPickBlockStack() : new ItemStack(Registries.ITEM.get(new Identifier("minecraft", "barrier"))); } -} \ No newline at end of file +} diff --git a/src/main/java/com/kqp/inventorytabs/tabs/tab/Tab.java b/src/main/java/com/kqp/inventorytabs/tabs/tab/Tab.java index 259e187..07cbaf0 100644 --- a/src/main/java/com/kqp/inventorytabs/tabs/tab/Tab.java +++ b/src/main/java/com/kqp/inventorytabs/tabs/tab/Tab.java @@ -6,6 +6,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.client.util.math.MatrixStack; @@ -62,19 +63,18 @@ public int getPriority() { /** * Renders the tab's icon * - * @param matrices MatrixStack + * @param context DrawContext * @param tabRenderInfo TabRenderInfo * @param currentScreen HandledScreen */ @Environment(EnvType.CLIENT) - public void renderTabIcon(MatrixStack matrices, TabRenderInfo tabRenderInfo, HandledScreen currentScreen) { - ItemRenderer itemRenderer = ((ScreenAccessor) currentScreen).getItemRenderer(); + public void renderTabIcon(DrawContext context, TabRenderInfo tabRenderInfo, HandledScreen currentScreen) { TextRenderer textRenderer = ((ScreenAccessor) currentScreen).getTextRenderer(); - matrices.push(); - matrices.translate(0, 0, 100.0F); + context.getMatrices().push(); + context.getMatrices().translate(0, 0, 100.0F); // RenderSystem.enableRescaleNormal(); - itemRenderer.renderInGuiWithOverrides(matrices, renderItemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); - itemRenderer.renderGuiItemOverlay(matrices, textRenderer, renderItemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); - matrices.pop(); + context.drawItem(renderItemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); + context.drawItemInSlot(textRenderer, renderItemStack, tabRenderInfo.itemX, tabRenderInfo.itemY); + context.getMatrices().pop(); } } diff --git a/src/main/java/com/kqp/inventorytabs/util/BlockUtil.java b/src/main/java/com/kqp/inventorytabs/util/BlockUtil.java index 01ef340..0b423b3 100644 --- a/src/main/java/com/kqp/inventorytabs/util/BlockUtil.java +++ b/src/main/java/com/kqp/inventorytabs/util/BlockUtil.java @@ -26,7 +26,7 @@ public static boolean inRange(BlockPos pos, PlayerEntity player, double distance return false; } public static BlockHitResult getLineOfSight(BlockPos pos, PlayerEntity player, double distance) { - World world = player.world; + World world = player.getWorld(); BlockState blockState = world.getBlockState(pos); double distanceSquared = distance * distance; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3b4709b..23225ea 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -34,8 +34,8 @@ "accessWidener": "inventorytabs.accesswidener", "depends": { "fabricloader": ">=0.14.19", - "fabric-api": ">=0.77.0", - "minecraft": ">=1.19.4", + "fabric-api": ">=0.81.2", + "minecraft": ">=1.20-beta.2", "cloth-config2": "*" }, "custom": { From 2d2c78487ed9a95568db26d54b42cc43cccecffa Mon Sep 17 00:00:00 2001 From: spiralhalo Date: Fri, 19 May 2023 22:33:23 +0700 Subject: [PATCH 2/4] Fixed crash on keybind screen, recover functionality --- ...get$KeyBindingEntryMixin_SoftConflict.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/kqp/inventorytabs/mixin/ControlsListWidget$KeyBindingEntryMixin_SoftConflict.java b/src/main/java/com/kqp/inventorytabs/mixin/ControlsListWidget$KeyBindingEntryMixin_SoftConflict.java index af502a3..59d2fd6 100644 --- a/src/main/java/com/kqp/inventorytabs/mixin/ControlsListWidget$KeyBindingEntryMixin_SoftConflict.java +++ b/src/main/java/com/kqp/inventorytabs/mixin/ControlsListWidget$KeyBindingEntryMixin_SoftConflict.java @@ -23,14 +23,21 @@ public class ControlsListWidget$KeyBindingEntryMixin_SoftConflict { @Shadow @Final private KeyBinding binding; - @ModifyArg(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/ButtonWidget;setMessage(Lnet/minecraft/text/Text;)V")) - public Text setMessage(Text text) { - TextColor c = text.getStyle().getColor(); - if(c != null && c.getRgb() == Objects.requireNonNull(Formatting.RED.getColorValue())) { - if(this.binding == InventoryTabsClient.NEXT_TAB_KEY_BIND) { - text = text.copy().formatted(Formatting.GOLD); - } + @ModifyArg(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/MutableText;formatted(Lnet/minecraft/util/Formatting;)Lnet/minecraft/text/MutableText;")) + public Formatting setBracketsColor(Formatting color) { + if (this.binding == InventoryTabsClient.NEXT_TAB_KEY_BIND && color.equals(Formatting.RED)) { + return Formatting.GOLD; } - return text; + + return color; + } + + @ModifyArg(index = 4, method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;fill(IIIII)V")) + public int setIndicatorColor(int color) { + if (this.binding == InventoryTabsClient.NEXT_TAB_KEY_BIND) { + return Formatting.GOLD.getColorValue() | 0xFF000000; + } + + return color; } } From 5e8340b1bfec42cd1f59e824a6fcc79851cd0bd5 Mon Sep 17 00:00:00 2001 From: spiralhalo Date: Fri, 19 May 2023 22:33:47 +0700 Subject: [PATCH 3/4] Update to 1.20-pre4 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 36840cd..d6adcdb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/versions.html - minecraft_version=1.20-pre2 - yarn_mappings=1.20-pre2+build.1 + minecraft_version=1.20-pre4 + yarn_mappings=1.20-pre4+build.1 loader_version=0.14.19 # Mod Properties From 72f6fbb1d8af10f79b42a5beb0c876e2d310cfe0 Mon Sep 17 00:00:00 2001 From: AshKetchum101 Date: Fri, 24 Nov 2023 20:30:41 +1100 Subject: [PATCH 4/4] Port to 1.20.1 Edit of GitUser spiralhalo's fork using code from Reddit u/Some_Professional392 --- gradle.properties | 4 ++-- src/main/resources/fabric.mod.json | 36 +++++++++--------------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/gradle.properties b/gradle.properties index d6adcdb..a4bfdf2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/versions.html - minecraft_version=1.20-pre4 - yarn_mappings=1.20-pre4+build.1 + minecraft_version=1.20.1 + yarn_mappings=1.20.1+build.1 loader_version=0.14.19 # Mod Properties diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 23225ea..ffae1af 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -4,11 +4,7 @@ "version": "${version}", "name": "Inventory Tabs", "description": "Adds tabs to your inventory that lead to nearby blocks.", - "authors": [ - "KQP", - "LiamMCW", - "Andrew6rant (Andrew Grant)" - ], + "authors": [ "KQP", "LiamMCW", "Andrew6rant (Andrew Grant)" ], "contact": { "homepage": "https://github.com/Andrew6rant/inventorytabs", "sources": "https://github.com/Andrew6rant/inventorytabs", @@ -18,34 +14,22 @@ "icon": "assets/inventorytabs/icon.png", "environment": "client", "entrypoints": { - "main": [ - "com.kqp.inventorytabs.init.InventoryTabs" - ], - "client": [ - "com.kqp.inventorytabs.init.InventoryTabsClient" - ], - "modmenu": [ - "com.kqp.inventorytabs.init.InventoryTabsModMenu" - ] + "main": [ "com.kqp.inventorytabs.init.InventoryTabs" ], + "client": [ "com.kqp.inventorytabs.init.InventoryTabsClient" ], + "modmenu": [ "com.kqp.inventorytabs.init.InventoryTabsModMenu" ] }, - "mixins": [ - "inventorytabs.mixins.json" - ], + "mixins": [ "inventorytabs.mixins.json" ], "accessWidener": "inventorytabs.accesswidener", "depends": { - "fabricloader": ">=0.14.19", - "fabric-api": ">=0.81.2", - "minecraft": ">=1.20-beta.2", + "fabricloader": ">=0.14.21", + "fabric-api": "*", + "minecraft": "~1.20.1", "cloth-config2": "*" }, - "custom": { - "modmenu": [ - "com.kqp.inventorytabs.init.InventoryTabsConfig" - ] - }, + "custom": { "modmenu": [ "com.kqp.inventorytabs.init.InventoryTabsConfig" ] }, "suggests": { "biginv": "*", "playerex": "*", "modmenu": "*" } -} +} \ No newline at end of file