From 9e55b44b710f38c63a4bfd17d0b07318d5c68535 Mon Sep 17 00:00:00 2001 From: Daniel She Date: Mon, 25 Feb 2019 21:18:26 +0800 Subject: REI v2.3.1 (#40) - API Changes - Updated Config Screen - Added Tipped Arrows Recipes - Updated Mappings - Added IRecipeHelper - Turning things to Optional - Removed Cheats button, now included with the new config button - Buttons for switching gamemodes / time / weather (default: off) [Maybe not in this update] - Clickable Labels - 3+ recipes at the same time - Fixed RecipeBaseWidget bad rendering when too big - Fixed #42 Patched up item deleting & cheating - Choose Page Dialog --- .../java/me/shedaniel/rei/client/ClientHelper.java | 34 +++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/main/java/me/shedaniel/rei/client/ClientHelper.java') diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelper.java b/src/main/java/me/shedaniel/rei/client/ClientHelper.java index 474fdf1ce..87dc00895 100644 --- a/src/main/java/me/shedaniel/rei/client/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/client/ClientHelper.java @@ -5,9 +5,10 @@ import io.netty.buffer.Unpooled; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.IRecipeCategory; import me.shedaniel.rei.api.IRecipeDisplay; +import me.shedaniel.rei.api.IRecipeHelper; import me.shedaniel.rei.gui.ContainerScreenOverlay; +import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.config.ConfigScreen; -import me.shedaniel.rei.gui.widget.RecipeViewingWidgetScreen; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; @@ -16,9 +17,11 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.Mouse; import net.minecraft.client.gui.Screen; +import net.minecraft.client.gui.ingame.CreativePlayerInventoryScreen; import net.minecraft.client.util.InputUtil; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.text.TranslatableTextComponent; import net.minecraft.util.DefaultedList; import net.minecraft.util.Identifier; import net.minecraft.util.PacketByteBuf; @@ -72,7 +75,7 @@ public class ClientHelper implements ClientModInitializer { } public static void sendDeletePacket() { - if (MinecraftClient.getInstance().interactionManager.hasCreativeInventory()) { + if (GuiHelper.getLastContainerScreen() instanceof CreativePlayerInventoryScreen) { MinecraftClient.getInstance().player.inventory.setCursorStack(ItemStack.EMPTY); return; } @@ -88,27 +91,31 @@ public class ClientHelper implements ClientModInitializer { return false; } } else { - Identifier location = Registry.ITEM.getId(cheatedStack.getItem()); + Identifier identifier = Registry.ITEM.getId(cheatedStack.getItem()); String tagMessage = cheatedStack.copy().getTag() != null && !cheatedStack.copy().getTag().isEmpty() ? cheatedStack.copy().getTag().asString() : ""; - String madeUpCommand = RoughlyEnoughItemsCore.getConfigHelper().getGiveCommandPrefix() + " " + MinecraftClient.getInstance().player.getEntityName() + " " + location.toString() + tagMessage + (cheatedStack.getAmount() != 1 ? " " + cheatedStack.getAmount() : ""); - if (madeUpCommand.length() > 256) - madeUpCommand = RoughlyEnoughItemsCore.getConfigHelper().getGiveCommandPrefix() + " " + MinecraftClient.getInstance().player.getEntityName() + " " + location.toString() + (cheatedStack.getAmount() != 1 ? " " + cheatedStack.getAmount() : ""); + String og = cheatedStack.getAmount() != 1 ? RoughlyEnoughItemsCore.getConfigHelper().getConfig().giveCommand.replaceAll(" \\{count}", "").replaceAll("\\{count}", "") : RoughlyEnoughItemsCore.getConfigHelper().getConfig().giveCommand; + String madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", tagMessage).replaceAll("\\{count}", String.valueOf(cheatedStack.getAmount())); + if (madeUpCommand.length() > 256) { + madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", "").replaceAll("\\{count}", String.valueOf(cheatedStack.getAmount())); + MinecraftClient.getInstance().player.addChatMessage(new TranslatableTextComponent("text.rei.too_long_nbt"), false); + } + System.out.println(madeUpCommand); MinecraftClient.getInstance().player.sendChatMessage(madeUpCommand); return true; } } public static boolean executeRecipeKeyBind(ContainerScreenOverlay overlay, ItemStack stack) { - Map> map = RecipeHelper.getInstance().getRecipesFor(stack); + Map> map = IRecipeHelper.getInstance().getRecipesFor(stack); if (map.keySet().size() > 0) - MinecraftClient.getInstance().openScreen(new RecipeViewingWidgetScreen(MinecraftClient.getInstance().window, map)); + MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); return map.keySet().size() > 0; } public static boolean executeUsageKeyBind(ContainerScreenOverlay overlay, ItemStack stack) { - Map> map = RecipeHelper.getInstance().getUsagesFor(stack); + Map> map = IRecipeHelper.getInstance().getUsagesFor(stack); if (map.keySet().size() > 0) - MinecraftClient.getInstance().openScreen(new RecipeViewingWidgetScreen(MinecraftClient.getInstance().window, map)); + MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); return map.keySet().size() > 0; } @@ -126,6 +133,13 @@ public class ClientHelper implements ClientModInitializer { return inventoryStacks; } + public static boolean executeViewAllRecipesKeyBind(ContainerScreenOverlay lastOverlay) { + Map> map = IRecipeHelper.getInstance().getAllRecipes(); + if (map.keySet().size() > 0) + MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); + return map.keySet().size() > 0; + } + @Override public void onInitializeClient() { this.cheating = false; -- cgit