From 8d55453299c0d6d4b749824fb1dc5c8096109703 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Tue, 21 Mar 2023 23:15:10 +0100 Subject: [PATCH 01/16] Add initial OptiGUI support There's a lot to add and to discuss --- build.gradle | 4 + .../quickshulker/client/ClientUtil.java | 83 ++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0d0a9d5..f24ee1f 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,7 @@ repositories { maven { url 'https://maven.fabricmc.net' } maven { url 'https://maven.kyrptonaught.dev' } maven { url "https://maven.terraformersmc.com/releases" } + maven { url "https://api.modrinth.com/maven" } } dependencies { @@ -37,6 +38,9 @@ dependencies { //shulkerutils modImplementation 'net.kyrptonaught:shulkerutils:1.0.4-1.19' include 'net.kyrptonaught:shulkerutils:1.0.4-1.19' + + //optigui + modImplementation ("maven.modrinth:optigui:2.0.0-beta.2") } tasks.withType(JavaCompile).configureEach { diff --git a/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java b/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java index c9fbcbd..7b87fb1 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java +++ b/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java @@ -10,11 +10,25 @@ import net.minecraft.item.ItemStack; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; +import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; +import opekope2.optifinecompat.properties.ChestProperties; +import opekope2.optifinecompat.properties.OptiFineProperties; +import opekope2.optifinecompat.properties.ShulkerBoxProperties; +import opekope2.optigui.interaction.InteractionTarget; +import opekope2.optigui.service.InteractionService; +import opekope2.optigui.service.RegistryLookupService; +import opekope2.optigui.service.Services; +import opekope2.util.TexturePath; public class ClientUtil { public static boolean CheckAndSend(ItemStack stack, int slot) { - if (Util.isOpenableItem(stack) && !Util.isBlockBlockingQuickOpen(MinecraftClient.getInstance().world, MinecraftClient.getInstance().player)) { + MinecraftClient client = MinecraftClient.getInstance(); + if (Util.isOpenableItem(stack) && !Util.isBlockBlockingQuickOpen(MinecraftClient.getInstance().world, client.player)) { + InteractionService interaction = Services.getService(InteractionService.class); + interaction.interact(client.player, client.world, Hand.MAIN_HAND, new InteractionTarget.Preprocessed(getInteractionTargetData(stack)), null); + SendOpenPacket(slot); return true; } @@ -49,4 +63,71 @@ public static int getPlayerInvSlot(ScreenHandler handler, Slot slot) { } return slot.getIndex(); } + + private static Object getInteractionTargetData(ItemStack stack) { + MinecraftClient client = MinecraftClient.getInstance(); + RegistryLookupService lookup = Services.getService(RegistryLookupService.class); + + String container = stack.getItem().toString(); + Identifier biome = lookup.lookupBiome(client.world, client.player.getBlockPos()); + String name = stack.hasCustomName() ? stack.getName().getString() : null; + + return switch (container) { + case "shulker_box", + "white_shulker_box", + "orange_shulker_box", + "magenta_shulker_box", + "light_blue_shulker_box", + "yellow_shulker_box", + "lime_shulker_box", + "pink_shulker_box", + "gray_shulker_box", + "light_gray_shulker_box", + "cyan_shulker_box", + "purple_shulker_box", + "blue_shulker_box", + "brown_shulker_box", + "green_shulker_box", + "red_shulker_box", + "black_shulker_box" -> new ShulkerBoxProperties( + "shulker_box", + TexturePath.SHULKER_BOX, + name, + biome, + client.player.getBlockY(), + getColorFromShulkerBox(container)); + case "ender_chest" -> new ChestProperties( + "chest", + TexturePath.GENERIC_54, + name, + biome, + client.player.getBlockY(), + false, + false, + false, + true, + false, + false); + case "crafting_table" -> new OptiFineProperties( + "crafting", + TexturePath.CRAFTING_TABLE, + name, + biome, + client.player.getBlockY()); + case "stonecutter" -> new OptiFineProperties( + "_stonecutter", + TexturePath.STONECUTTER, + name, + biome, + client.player.getBlockY()); + default -> null; + }; + } + + private static String getColorFromShulkerBox(String itemName) { + assert itemName.endsWith("shulker_box"); + + String color = itemName.substring(0, itemName.length() - "shulker_box".length()); + return color.isEmpty() ? null : color.substring(0, color.length() - 1); + } } From 6f0157ed68f3b778ae265d66b0450cc4a0600bd2 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Tue, 21 Mar 2023 23:20:30 +0100 Subject: [PATCH 02/16] Mark dependent on optigui --- src/main/resources/fabric.mod.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d7ddef4..ecc14de 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -37,7 +37,8 @@ "depends": { "fabricloader": ">=0.12.5", "fabric": "*", - "java": ">=17" + "java": ">=17", + "optigui": ">=2.0.0-beta.2" }, "accessWidener": "quickshulker.accesswidener" } From 1bb00f81b01c4056dbf60c122f4bd98cc78c4dc5 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 25 Mar 2023 02:12:53 +0100 Subject: [PATCH 03/16] Update OptiGUI --- build.gradle | 2 +- .../quickshulker/client/ClientUtil.java | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index f24ee1f..fac68da 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ dependencies { include 'net.kyrptonaught:shulkerutils:1.0.4-1.19' //optigui - modImplementation ("maven.modrinth:optigui:2.0.0-beta.2") + modImplementation ("maven.modrinth:optigui:2.0.0-beta.3") } tasks.withType(JavaCompile).configureEach { diff --git a/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java b/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java index 7b87fb1..9c7af8f 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java +++ b/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java @@ -64,7 +64,7 @@ public static int getPlayerInvSlot(ScreenHandler handler, Slot slot) { return slot.getIndex(); } - private static Object getInteractionTargetData(ItemStack stack) { + public static Object getInteractionTargetData(ItemStack stack) { MinecraftClient client = MinecraftClient.getInstance(); RegistryLookupService lookup = Services.getService(RegistryLookupService.class); @@ -90,15 +90,11 @@ private static Object getInteractionTargetData(ItemStack stack) { "green_shulker_box", "red_shulker_box", "black_shulker_box" -> new ShulkerBoxProperties( - "shulker_box", - TexturePath.SHULKER_BOX, name, biome, client.player.getBlockY(), getColorFromShulkerBox(container)); case "ender_chest" -> new ChestProperties( - "chest", - TexturePath.GENERIC_54, name, biome, client.player.getBlockY(), @@ -108,15 +104,7 @@ private static Object getInteractionTargetData(ItemStack stack) { true, false, false); - case "crafting_table" -> new OptiFineProperties( - "crafting", - TexturePath.CRAFTING_TABLE, - name, - biome, - client.player.getBlockY()); - case "stonecutter" -> new OptiFineProperties( - "_stonecutter", - TexturePath.STONECUTTER, + case "crafting_table", "stonecutter" -> new OptiFineProperties( name, biome, client.player.getBlockY()); From 6cc5f21fbb6166901ac7ba9f05a5bc4a2b2fb00c Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 25 Mar 2023 02:19:50 +0100 Subject: [PATCH 04/16] Add support for inventory switching --- .../quickshulker/QuickShulkerMod.java | 21 +++++++++++++++---- .../client/QuickShulkerModClient.java | 16 ++++++++++++++ .../network/OpenQuickiePacket.java | 20 ++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/kyrptonaught/quickshulker/network/OpenQuickiePacket.java diff --git a/src/main/java/net/kyrptonaught/quickshulker/QuickShulkerMod.java b/src/main/java/net/kyrptonaught/quickshulker/QuickShulkerMod.java index eee1d1d..91bf426 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/QuickShulkerMod.java +++ b/src/main/java/net/kyrptonaught/quickshulker/QuickShulkerMod.java @@ -6,19 +6,24 @@ import net.kyrptonaught.kyrptconfig.config.ConfigManager; import net.kyrptonaught.quickshulker.api.*; import net.kyrptonaught.quickshulker.config.ConfigOptions; +import net.kyrptonaught.quickshulker.network.OpenQuickiePacket; import net.kyrptonaught.quickshulker.network.OpenShulkerPacket; import net.kyrptonaught.quickshulker.network.QuickBundlePacket; import net.minecraft.block.CraftingTableBlock; import net.minecraft.block.EnderChestBlock; import net.minecraft.block.ShulkerBoxBlock; import net.minecraft.block.StonecutterBlock; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; import net.minecraft.screen.*; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; +import java.util.function.BiConsumer; + public class QuickShulkerMod implements ModInitializer, RegisterQuickShulker { public static final String MOD_ID = "quickshulker"; @@ -58,7 +63,7 @@ public void registerProviders() { new QuickOpenableRegistry.Builder() .setItem(ShulkerBoxBlock.class) .supportsBundleing(true) - .setOpenAction(((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> + .setOpenAction(wrapOpenAction((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> new ShulkerBoxScreenHandler(i, player.getInventory(), new ItemStackInventory(stack, 27)), stack.hasCustomName() ? stack.getName() : Text.translatable("container.shulkerBox"))))) .register(); @@ -67,7 +72,7 @@ public void registerProviders() { .setItem(EnderChestBlock.class) .supportsBundleing(true) .ignoreSingleStackCheck(true) - .setOpenAction(((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> + .setOpenAction(wrapOpenAction((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, player.getEnderChestInventory()), Text.translatable("container.enderchest"))))) .register(); @@ -75,7 +80,7 @@ public void registerProviders() { new QuickOpenableRegistry.Builder() .setItem(CraftingTableBlock.class) .ignoreSingleStackCheck(true) - .setOpenAction(((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> + .setOpenAction(wrapOpenAction((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> new CraftingScreenHandler(i, playerInventory, ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos())), Text.translatable("container.crafting"))))) .register(); @@ -83,8 +88,16 @@ public void registerProviders() { new QuickOpenableRegistry.Builder() .setItem(StonecutterBlock.class) .ignoreSingleStackCheck(true) - .setOpenAction(((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> + .setOpenAction(wrapOpenAction((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> new StonecutterScreenHandler(i, playerInventory, ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos())), Text.translatable("container.stonecutter"))))) .register(); } + + private BiConsumer wrapOpenAction(BiConsumer openAction) { + return ((player, stack) -> { + ((ServerPlayerEntity) player).closeHandledScreen(); + OpenQuickiePacket.send((ServerPlayerEntity) player, stack); + openAction.accept(player, stack); + }); + } } diff --git a/src/main/java/net/kyrptonaught/quickshulker/client/QuickShulkerModClient.java b/src/main/java/net/kyrptonaught/quickshulker/client/QuickShulkerModClient.java index df346fa..a0b3fba 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/client/QuickShulkerModClient.java +++ b/src/main/java/net/kyrptonaught/quickshulker/client/QuickShulkerModClient.java @@ -12,9 +12,17 @@ import net.kyrptonaught.quickshulker.QuickShulkerMod; import net.kyrptonaught.quickshulker.api.RegisterQuickShulkerClient; import net.kyrptonaught.quickshulker.network.OpenInventoryPacket; +import net.kyrptonaught.quickshulker.network.OpenQuickiePacket; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.InventoryScreen; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import opekope2.optigui.interaction.InteractionTarget; +import opekope2.optigui.service.InteractionService; +import opekope2.optigui.service.Services; + +import static net.kyrptonaught.quickshulker.client.ClientUtil.getInteractionTargetData; @Environment(EnvType.CLIENT) public class QuickShulkerModClient implements ClientModInitializer { @@ -37,6 +45,14 @@ public void onInitializeClient() { client.setScreen(new InventoryScreen(client.player)); }); }); + ClientPlayNetworking.registerGlobalReceiver(OpenQuickiePacket.OPEN_QUICKIE, (client, handler, packet, sender) -> { + ItemStack stack = packet.readItemStack(); + + client.execute(() -> { + InteractionService interaction = Services.getService(InteractionService.class); + interaction.interact(client.player, client.world, Hand.MAIN_HAND, new InteractionTarget.Preprocessed(getInteractionTargetData(stack)), null); + }); + }); FabricLoader.getInstance().getEntrypoints(QuickShulkerMod.MOD_ID + "_client", RegisterQuickShulkerClient.class).forEach(RegisterQuickShulkerClient::registerClient); KeyBindingHelper.registerKeyBinding(new DisplayOnlyKeyBind( diff --git a/src/main/java/net/kyrptonaught/quickshulker/network/OpenQuickiePacket.java b/src/main/java/net/kyrptonaught/quickshulker/network/OpenQuickiePacket.java new file mode 100644 index 0000000..88831ed --- /dev/null +++ b/src/main/java/net/kyrptonaught/quickshulker/network/OpenQuickiePacket.java @@ -0,0 +1,20 @@ +package net.kyrptonaught.quickshulker.network; + +import io.netty.buffer.Unpooled; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.kyrptonaught.quickshulker.QuickShulkerMod; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class OpenQuickiePacket { + public static final Identifier OPEN_QUICKIE = new Identifier(QuickShulkerMod.MOD_ID, "openquickie"); + + public static void send(ServerPlayerEntity player, ItemStack stack) { + PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); + buf.writeItemStack(stack); + ServerPlayNetworking.send(player, OPEN_QUICKIE, new PacketByteBuf(buf)); + } + +} From 1a0e77f9e752a1bc1b16ffbf9563609c88932f70 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 25 Mar 2023 02:22:15 +0100 Subject: [PATCH 05/16] Revert CheckAndSend changes OptiGUI interaction happens elsewhere --- .../kyrptonaught/quickshulker/client/ClientUtil.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java b/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java index 9c7af8f..4284bd2 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java +++ b/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java @@ -6,29 +6,20 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; -import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import opekope2.optifinecompat.properties.ChestProperties; import opekope2.optifinecompat.properties.OptiFineProperties; import opekope2.optifinecompat.properties.ShulkerBoxProperties; -import opekope2.optigui.interaction.InteractionTarget; -import opekope2.optigui.service.InteractionService; import opekope2.optigui.service.RegistryLookupService; import opekope2.optigui.service.Services; -import opekope2.util.TexturePath; public class ClientUtil { public static boolean CheckAndSend(ItemStack stack, int slot) { - MinecraftClient client = MinecraftClient.getInstance(); - if (Util.isOpenableItem(stack) && !Util.isBlockBlockingQuickOpen(MinecraftClient.getInstance().world, client.player)) { - InteractionService interaction = Services.getService(InteractionService.class); - interaction.interact(client.player, client.world, Hand.MAIN_HAND, new InteractionTarget.Preprocessed(getInteractionTargetData(stack)), null); - + if (Util.isOpenableItem(stack) && !Util.isBlockBlockingQuickOpen(MinecraftClient.getInstance().world, MinecraftClient.getInstance().player)) { SendOpenPacket(slot); return true; } From 75ac2f646456c77fcfe0421d431456cefd5e2113 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 25 Mar 2023 03:28:06 +0100 Subject: [PATCH 06/16] Bump OptiGUI in fabric.mod.json --- src/main/resources/fabric.mod.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ecc14de..a8c364d 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -38,7 +38,7 @@ "fabricloader": ">=0.12.5", "fabric": "*", "java": ">=17", - "optigui": ">=2.0.0-beta.2" + "optigui": ">=2.0.0-beta.3" }, "accessWidener": "quickshulker.accesswidener" } From 604182d53292f28d4cd24a3a7911cbbf55ef2e7a Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 25 Mar 2023 15:25:00 +0100 Subject: [PATCH 07/16] Add OptiGUI wrapper --- .../quickshulker/optigui/Initializer.java | 87 +++++++++++++++++++ .../optigui/InteractionWrapper.java | 26 ++++++ src/main/resources/fabric.mod.json | 3 + 3 files changed, 116 insertions(+) create mode 100644 src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java create mode 100644 src/main/java/net/kyrptonaught/quickshulker/optigui/InteractionWrapper.java diff --git a/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java b/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java new file mode 100644 index 0000000..8f59fb0 --- /dev/null +++ b/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java @@ -0,0 +1,87 @@ +package net.kyrptonaught.quickshulker.optigui; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; +import net.minecraft.world.World; +import opekope2.optifinecompat.properties.ChestProperties; +import opekope2.optifinecompat.properties.OptiFineProperties; +import opekope2.optifinecompat.properties.ShulkerBoxProperties; +import opekope2.optigui.EntryPoint; +import opekope2.optigui.InitializerContext; +import opekope2.optigui.interaction.InteractionTarget; +import opekope2.optigui.service.InteractionService; +import opekope2.optigui.service.RegistryLookupService; +import opekope2.optigui.service.Services; +import org.jetbrains.annotations.NotNull; + +public class Initializer implements EntryPoint { + @Override + public void onInitialize(@NotNull InitializerContext initializerContext) { + InteractionWrapper.setImpl(new InteractionWrapper() { + private final InteractionService interactionService = Services.getService(InteractionService.class); + + @Override + public void interact(@NotNull PlayerEntity player, @NotNull World world, @NotNull Hand hand, @NotNull ItemStack item) { + interactionService.interact(player, world, hand, new InteractionTarget.Preprocessed(getInteractionTargetData(item)), null); + } + }); + } + + private static Object getInteractionTargetData(ItemStack stack) { + MinecraftClient client = MinecraftClient.getInstance(); + RegistryLookupService lookup = Services.getService(RegistryLookupService.class); + + String container = stack.getItem().toString(); + Identifier biome = lookup.lookupBiome(client.world, client.player.getBlockPos()); + String name = stack.hasCustomName() ? stack.getName().getString() : null; + + return switch (container) { + case "shulker_box", + "white_shulker_box", + "orange_shulker_box", + "magenta_shulker_box", + "light_blue_shulker_box", + "yellow_shulker_box", + "lime_shulker_box", + "pink_shulker_box", + "gray_shulker_box", + "light_gray_shulker_box", + "cyan_shulker_box", + "purple_shulker_box", + "blue_shulker_box", + "brown_shulker_box", + "green_shulker_box", + "red_shulker_box", + "black_shulker_box" -> new ShulkerBoxProperties( + name, + biome, + client.player.getBlockY(), + getColorFromShulkerBox(container)); + case "ender_chest" -> new ChestProperties( + name, + biome, + client.player.getBlockY(), + false, + false, + false, + true, + false, + false); + case "crafting_table", "stonecutter" -> new OptiFineProperties( + name, + biome, + client.player.getBlockY()); + default -> null; + }; + } + + private static String getColorFromShulkerBox(String itemName) { + assert itemName.endsWith("shulker_box"); + + String color = itemName.substring(0, itemName.length() - "shulker_box".length()); + return color.isEmpty() ? null : color.substring(0, color.length() - 1); + } +} diff --git a/src/main/java/net/kyrptonaught/quickshulker/optigui/InteractionWrapper.java b/src/main/java/net/kyrptonaught/quickshulker/optigui/InteractionWrapper.java new file mode 100644 index 0000000..ede12a2 --- /dev/null +++ b/src/main/java/net/kyrptonaught/quickshulker/optigui/InteractionWrapper.java @@ -0,0 +1,26 @@ +package net.kyrptonaught.quickshulker.optigui; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; + +public abstract class InteractionWrapper { + private static final InteractionWrapper dummy = new InteractionWrapper() { + @Override + public void interact(@NotNull PlayerEntity player, @NotNull World world, @NotNull Hand hand, @NotNull ItemStack item) { + } + }; + private static InteractionWrapper impl = dummy; + + public static InteractionWrapper getImpl() { + return impl; + } + + public static void setImpl(InteractionWrapper impl) { + InteractionWrapper.impl = impl != null ? impl : dummy; + } + + public abstract void interact(@NotNull PlayerEntity player, @NotNull World world, @NotNull Hand hand, @NotNull ItemStack item); +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a8c364d..2ec183b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -32,6 +32,9 @@ ], "modmenu": [ "net.kyrptonaught.quickshulker.config.modmenu.ModMenuIntegration" + ], + "optigui": [ + "net.kyrptonaught.quickshulker.optigui.Initializer" ] }, "depends": { From 27f19587eca6c8ddc32845c0960a5e8eb932b73b Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 25 Mar 2023 15:26:18 +0100 Subject: [PATCH 08/16] Update code to use the wrapper --- .../quickshulker/client/QuickShulkerModClient.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/kyrptonaught/quickshulker/client/QuickShulkerModClient.java b/src/main/java/net/kyrptonaught/quickshulker/client/QuickShulkerModClient.java index a0b3fba..b597631 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/client/QuickShulkerModClient.java +++ b/src/main/java/net/kyrptonaught/quickshulker/client/QuickShulkerModClient.java @@ -13,16 +13,12 @@ import net.kyrptonaught.quickshulker.api.RegisterQuickShulkerClient; import net.kyrptonaught.quickshulker.network.OpenInventoryPacket; import net.kyrptonaught.quickshulker.network.OpenQuickiePacket; +import net.kyrptonaught.quickshulker.optigui.InteractionWrapper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.InventoryScreen; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; -import opekope2.optigui.interaction.InteractionTarget; -import opekope2.optigui.service.InteractionService; -import opekope2.optigui.service.Services; - -import static net.kyrptonaught.quickshulker.client.ClientUtil.getInteractionTargetData; @Environment(EnvType.CLIENT) public class QuickShulkerModClient implements ClientModInitializer { @@ -49,8 +45,7 @@ public void onInitializeClient() { ItemStack stack = packet.readItemStack(); client.execute(() -> { - InteractionService interaction = Services.getService(InteractionService.class); - interaction.interact(client.player, client.world, Hand.MAIN_HAND, new InteractionTarget.Preprocessed(getInteractionTargetData(stack)), null); + InteractionWrapper.getImpl().interact(client.player, client.world, Hand.MAIN_HAND, stack); }); }); FabricLoader.getInstance().getEntrypoints(QuickShulkerMod.MOD_ID + "_client", RegisterQuickShulkerClient.class).forEach(RegisterQuickShulkerClient::registerClient); From 6d41761a8e4e29c7cf3f7fe38b21020eb9fa836a Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 25 Mar 2023 15:26:55 +0100 Subject: [PATCH 09/16] Remove unused code duplication --- .../quickshulker/client/ClientUtil.java | 61 ------------------- 1 file changed, 61 deletions(-) diff --git a/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java b/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java index 4284bd2..eec06f4 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java +++ b/src/main/java/net/kyrptonaught/quickshulker/client/ClientUtil.java @@ -9,12 +9,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; -import net.minecraft.util.Identifier; -import opekope2.optifinecompat.properties.ChestProperties; -import opekope2.optifinecompat.properties.OptiFineProperties; -import opekope2.optifinecompat.properties.ShulkerBoxProperties; -import opekope2.optigui.service.RegistryLookupService; -import opekope2.optigui.service.Services; public class ClientUtil { @@ -54,59 +48,4 @@ public static int getPlayerInvSlot(ScreenHandler handler, Slot slot) { } return slot.getIndex(); } - - public static Object getInteractionTargetData(ItemStack stack) { - MinecraftClient client = MinecraftClient.getInstance(); - RegistryLookupService lookup = Services.getService(RegistryLookupService.class); - - String container = stack.getItem().toString(); - Identifier biome = lookup.lookupBiome(client.world, client.player.getBlockPos()); - String name = stack.hasCustomName() ? stack.getName().getString() : null; - - return switch (container) { - case "shulker_box", - "white_shulker_box", - "orange_shulker_box", - "magenta_shulker_box", - "light_blue_shulker_box", - "yellow_shulker_box", - "lime_shulker_box", - "pink_shulker_box", - "gray_shulker_box", - "light_gray_shulker_box", - "cyan_shulker_box", - "purple_shulker_box", - "blue_shulker_box", - "brown_shulker_box", - "green_shulker_box", - "red_shulker_box", - "black_shulker_box" -> new ShulkerBoxProperties( - name, - biome, - client.player.getBlockY(), - getColorFromShulkerBox(container)); - case "ender_chest" -> new ChestProperties( - name, - biome, - client.player.getBlockY(), - false, - false, - false, - true, - false, - false); - case "crafting_table", "stonecutter" -> new OptiFineProperties( - name, - biome, - client.player.getBlockY()); - default -> null; - }; - } - - private static String getColorFromShulkerBox(String itemName) { - assert itemName.endsWith("shulker_box"); - - String color = itemName.substring(0, itemName.length() - "shulker_box".length()); - return color.isEmpty() ? null : color.substring(0, color.length() - 1); - } } From bbd23c44198c3045c887138d139d731876106b7c Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 25 Mar 2023 15:30:12 +0100 Subject: [PATCH 10/16] Remove optigui as a required dependency --- src/main/resources/fabric.mod.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2ec183b..dc4f10d 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -40,8 +40,7 @@ "depends": { "fabricloader": ">=0.12.5", "fabric": "*", - "java": ">=17", - "optigui": ">=2.0.0-beta.3" + "java": ">=17" }, "accessWidener": "quickshulker.accesswidener" } From 10efe85b8067f27db4a92490951e850be12213a3 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Thu, 1 Jun 2023 01:21:44 +0200 Subject: [PATCH 11/16] Update OptiGUI to 2.1.0-beta.3 --- build.gradle | 5 +- .../quickshulker/optigui/Initializer.java | 59 +++---------------- 2 files changed, 12 insertions(+), 52 deletions(-) diff --git a/build.gradle b/build.gradle index fac68da..0f5a8f3 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,8 @@ dependencies { include 'net.kyrptonaught:shulkerutils:1.0.4-1.19' //optigui - modImplementation ("maven.modrinth:optigui:2.0.0-beta.3") + modCompileOnly ("maven.modrinth:optigui:2.1.0-beta.3") + modLocalRuntime ("maven.modrinth:optigui:2.1.0-beta.3") } tasks.withType(JavaCompile).configureEach { @@ -74,4 +75,4 @@ publishing { } } } -} \ No newline at end of file +} diff --git a/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java b/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java index 8f59fb0..1b04e98 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java +++ b/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java @@ -3,15 +3,14 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.registry.Registries; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.world.World; -import opekope2.optifinecompat.properties.ChestProperties; -import opekope2.optifinecompat.properties.OptiFineProperties; -import opekope2.optifinecompat.properties.ShulkerBoxProperties; import opekope2.optigui.EntryPoint; import opekope2.optigui.InitializerContext; import opekope2.optigui.interaction.InteractionTarget; +import opekope2.optigui.properties.DefaultProperties; import opekope2.optigui.service.InteractionService; import opekope2.optigui.service.RegistryLookupService; import opekope2.optigui.service.Services; @@ -34,54 +33,14 @@ private static Object getInteractionTargetData(ItemStack stack) { MinecraftClient client = MinecraftClient.getInstance(); RegistryLookupService lookup = Services.getService(RegistryLookupService.class); - String container = stack.getItem().toString(); - Identifier biome = lookup.lookupBiome(client.world, client.player.getBlockPos()); + Identifier biome = lookup.lookupBiomeId(client.world, client.player.getBlockPos()); String name = stack.hasCustomName() ? stack.getName().getString() : null; - return switch (container) { - case "shulker_box", - "white_shulker_box", - "orange_shulker_box", - "magenta_shulker_box", - "light_blue_shulker_box", - "yellow_shulker_box", - "lime_shulker_box", - "pink_shulker_box", - "gray_shulker_box", - "light_gray_shulker_box", - "cyan_shulker_box", - "purple_shulker_box", - "blue_shulker_box", - "brown_shulker_box", - "green_shulker_box", - "red_shulker_box", - "black_shulker_box" -> new ShulkerBoxProperties( - name, - biome, - client.player.getBlockY(), - getColorFromShulkerBox(container)); - case "ender_chest" -> new ChestProperties( - name, - biome, - client.player.getBlockY(), - false, - false, - false, - true, - false, - false); - case "crafting_table", "stonecutter" -> new OptiFineProperties( - name, - biome, - client.player.getBlockY()); - default -> null; - }; - } - - private static String getColorFromShulkerBox(String itemName) { - assert itemName.endsWith("shulker_box"); - - String color = itemName.substring(0, itemName.length() - "shulker_box".length()); - return color.isEmpty() ? null : color.substring(0, color.length() - 1); + return new DefaultProperties( + Registries.ITEM.getId(stack.getItem()), + name, + biome, + client.player.getBlockY() + ); } } From b531061e5ede8de8d50ee83f784408a318790fcb Mon Sep 17 00:00:00 2001 From: opekope2 Date: Thu, 1 Jun 2023 01:31:58 +0200 Subject: [PATCH 12/16] Rename openquickie packet ID to open_quickie --- .../kyrptonaught/quickshulker/network/OpenQuickiePacket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kyrptonaught/quickshulker/network/OpenQuickiePacket.java b/src/main/java/net/kyrptonaught/quickshulker/network/OpenQuickiePacket.java index 88831ed..4c6a3bd 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/network/OpenQuickiePacket.java +++ b/src/main/java/net/kyrptonaught/quickshulker/network/OpenQuickiePacket.java @@ -9,7 +9,7 @@ import net.minecraft.util.Identifier; public class OpenQuickiePacket { - public static final Identifier OPEN_QUICKIE = new Identifier(QuickShulkerMod.MOD_ID, "openquickie"); + public static final Identifier OPEN_QUICKIE = new Identifier(QuickShulkerMod.MOD_ID, "open_quickie"); public static void send(ServerPlayerEntity player, ItemStack stack) { PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); From a06111ad9f9f707beab3605958f69a60d65aa090 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Thu, 1 Jun 2023 01:34:12 +0200 Subject: [PATCH 13/16] Merge wrapOpenAction into the wrapped action Remove excess parentheses --- .../quickshulker/QuickShulkerMod.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/kyrptonaught/quickshulker/QuickShulkerMod.java b/src/main/java/net/kyrptonaught/quickshulker/QuickShulkerMod.java index 91bf426..81e0cb3 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/QuickShulkerMod.java +++ b/src/main/java/net/kyrptonaught/quickshulker/QuickShulkerMod.java @@ -13,7 +13,6 @@ import net.minecraft.block.EnderChestBlock; import net.minecraft.block.ShulkerBoxBlock; import net.minecraft.block.StonecutterBlock; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; import net.minecraft.screen.*; @@ -22,8 +21,6 @@ import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; -import java.util.function.BiConsumer; - public class QuickShulkerMod implements ModInitializer, RegisterQuickShulker { public static final String MOD_ID = "quickshulker"; @@ -63,8 +60,12 @@ public void registerProviders() { new QuickOpenableRegistry.Builder() .setItem(ShulkerBoxBlock.class) .supportsBundleing(true) - .setOpenAction(wrapOpenAction((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> - new ShulkerBoxScreenHandler(i, player.getInventory(), new ItemStackInventory(stack, 27)), stack.hasCustomName() ? stack.getName() : Text.translatable("container.shulkerBox"))))) + .setOpenAction((player, stack) -> { + ((ServerPlayerEntity) player).closeHandledScreen(); + OpenQuickiePacket.send((ServerPlayerEntity) player, stack); + player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> + new ShulkerBoxScreenHandler(i, player.getInventory(), new ItemStackInventory(stack, 27)), stack.hasCustomName() ? stack.getName() : Text.translatable("container.shulkerBox"))); + }) .register(); if (getConfig().quickEChest) @@ -72,32 +73,36 @@ public void registerProviders() { .setItem(EnderChestBlock.class) .supportsBundleing(true) .ignoreSingleStackCheck(true) - .setOpenAction(wrapOpenAction((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> - GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, player.getEnderChestInventory()), Text.translatable("container.enderchest"))))) + .setOpenAction((player, stack) -> { + ((ServerPlayerEntity) player).closeHandledScreen(); + OpenQuickiePacket.send((ServerPlayerEntity) player, stack); + player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> + GenericContainerScreenHandler.createGeneric9x3(i, playerInventory, player.getEnderChestInventory()), Text.translatable("container.enderchest"))); + }) .register(); if (getConfig().quickCraftingTables) new QuickOpenableRegistry.Builder() .setItem(CraftingTableBlock.class) .ignoreSingleStackCheck(true) - .setOpenAction(wrapOpenAction((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> - new CraftingScreenHandler(i, playerInventory, ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos())), Text.translatable("container.crafting"))))) + .setOpenAction((player, stack) -> { + ((ServerPlayerEntity) player).closeHandledScreen(); + OpenQuickiePacket.send((ServerPlayerEntity) player, stack); + player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> + new CraftingScreenHandler(i, playerInventory, ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos())), Text.translatable("container.crafting"))); + }) .register(); if (getConfig().quickStonecutter) new QuickOpenableRegistry.Builder() .setItem(StonecutterBlock.class) .ignoreSingleStackCheck(true) - .setOpenAction(wrapOpenAction((player, stack) -> player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> - new StonecutterScreenHandler(i, playerInventory, ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos())), Text.translatable("container.stonecutter"))))) + .setOpenAction((player, stack) -> { + ((ServerPlayerEntity) player).closeHandledScreen(); + OpenQuickiePacket.send((ServerPlayerEntity) player, stack); + player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> + new StonecutterScreenHandler(i, playerInventory, ScreenHandlerContext.create(player.getEntityWorld(), player.getBlockPos())), Text.translatable("container.stonecutter"))); + }) .register(); } - - private BiConsumer wrapOpenAction(BiConsumer openAction) { - return ((player, stack) -> { - ((ServerPlayerEntity) player).closeHandledScreen(); - OpenQuickiePacket.send((ServerPlayerEntity) player, stack); - openAction.accept(player, stack); - }); - } } From 703ac89c49c3311b854a7da51da3cfe91eb2059b Mon Sep 17 00:00:00 2001 From: opekope2 Date: Thu, 1 Jun 2023 01:34:35 +0200 Subject: [PATCH 14/16] Add exec perm to gradlew --- gradlew | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From 4ea873ec44f6c42b76c939330861dbb603fc8cab Mon Sep 17 00:00:00 2001 From: opekope2 Date: Thu, 1 Jun 2023 02:15:33 +0200 Subject: [PATCH 15/16] Downgrade OptiGUI compile version to 2.1.0-beta.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0f5a8f3..fe70c0f 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ dependencies { include 'net.kyrptonaught:shulkerutils:1.0.4-1.19' //optigui - modCompileOnly ("maven.modrinth:optigui:2.1.0-beta.3") + modCompileOnly ("maven.modrinth:optigui:2.1.0-beta.1") modLocalRuntime ("maven.modrinth:optigui:2.1.0-beta.3") } From 52606a187635ad78331cc0176b24fc5d031aa6b6 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Thu, 1 Jun 2023 02:18:20 +0200 Subject: [PATCH 16/16] Add check for OptiGUI version --- .../quickshulker/optigui/Initializer.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java b/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java index 1b04e98..7f76cbe 100644 --- a/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java +++ b/src/main/java/net/kyrptonaught/quickshulker/optigui/Initializer.java @@ -1,5 +1,6 @@ package net.kyrptonaught.quickshulker.optigui; +import net.fabricmc.loader.api.*; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -16,9 +17,31 @@ import opekope2.optigui.service.Services; import org.jetbrains.annotations.NotNull; +import java.util.Optional; + public class Initializer implements EntryPoint { @Override public void onInitialize(@NotNull InitializerContext initializerContext) { + final Version optiGuiMinVersion; + try { + optiGuiMinVersion = SemanticVersion.parse("2.1.0-beta.1"); + } catch (VersionParsingException e) { + // Should never happen + return; + } + + Optional optigui = FabricLoader.getInstance().getModContainer("optigui"); + if (optigui.isEmpty()) { + // OptiGUI not loaded. Some other mod called this entry point + return; + } + + Version optiGuiVersion = optigui.get().getMetadata().getVersion(); + if (optiGuiVersion.compareTo(optiGuiMinVersion) < 0) { + // OptiGUI too old, will crash with MethodNotFoundException or sth because of the breaking changes + return; + } + InteractionWrapper.setImpl(new InteractionWrapper() { private final InteractionService interactionService = Services.getService(InteractionService.class);