Bladeren bron

Basic Config

Unknown 6 jaren geleden
bovenliggende
commit
79249bdf32

+ 1 - 1
build.gradle

@@ -6,7 +6,7 @@ sourceCompatibility = 1.8
 targetCompatibility = 1.8
 
 archivesBaseName = "RoughlyEnoughItems"
-version = "2.0.0.32"
+version = "2.0.0.33"
 
 minecraft {
 }

+ 5 - 5
src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java

@@ -2,7 +2,7 @@ package me.shedaniel.rei;
 
 import me.shedaniel.rei.api.IRecipePlugin;
 import me.shedaniel.rei.client.ClientHelper;
-import me.shedaniel.rei.client.ConfigManager;
+import me.shedaniel.rei.client.ConfigHelper;
 import me.shedaniel.rei.client.RecipeHelper;
 import me.shedaniel.rei.listeners.IListener;
 import me.shedaniel.rei.plugin.DefaultPlugin;
@@ -27,7 +27,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
     public static final Identifier DELETE_ITEMS_PACKET = new Identifier("roughlyenoughitems", "deleteitem");
     public static final Identifier CREATE_ITEMS_PACKET = new Identifier("roughlyenoughitems", "createitem");
     private static final List<IListener> listeners = new ArrayList<>();
-    private static ConfigManager configManager;
+    private static ConfigHelper configHelper;
     
     public static <T> List<T> getListeners(Class<T> listenerClass) {
         return listeners.stream().filter(listener -> {
@@ -37,15 +37,15 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
         }).collect(Collectors.toList());
     }
     
-    public static ConfigManager getConfigManager() {
-        return configManager;
+    public static ConfigHelper getConfigHelper() {
+        return configHelper;
     }
     
     @Override
     public void onInitializeClient() {
         registerREIListeners();
         registerDefaultPlugin();
-        configManager = new ConfigManager();
+        configHelper = new ConfigHelper();
     }
     
     private void registerDefaultPlugin() {

+ 24 - 2
src/main/java/me/shedaniel/rei/client/ClientHelper.java

@@ -6,6 +6,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsCore;
 import me.shedaniel.rei.api.IRecipeCategory;
 import me.shedaniel.rei.api.IRecipeDisplay;
 import me.shedaniel.rei.gui.ContainerGuiOverlay;
+import me.shedaniel.rei.gui.widget.ConfigWidget;
 import me.shedaniel.rei.gui.widget.RecipeViewingWidget;
 import me.shedaniel.rei.listeners.ClientLoaded;
 import me.shedaniel.rei.listeners.IMixinContainerGui;
@@ -15,6 +16,8 @@ import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl;
 import net.fabricmc.loader.FabricLoader;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.Mouse;
+import net.minecraft.client.gui.ContainerGui;
+import net.minecraft.client.gui.Gui;
 import net.minecraft.client.resource.language.I18n;
 import net.minecraft.client.util.InputUtil;
 import net.minecraft.enchantment.Enchantment;
@@ -23,6 +26,7 @@ import net.minecraft.item.Item;
 import net.minecraft.item.ItemStack;
 import net.minecraft.item.Items;
 import net.minecraft.server.network.packet.CustomPayloadServerPacket;
+import net.minecraft.util.DefaultedList;
 import net.minecraft.util.Identifier;
 import net.minecraft.util.PacketByteBuf;
 import net.minecraft.util.registry.Registry;
@@ -30,6 +34,7 @@ import net.minecraft.util.registry.Registry;
 import java.awt.*;
 import java.awt.event.KeyEvent;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
@@ -117,9 +122,16 @@ public class ClientHelper implements ClientLoaded, ClientModInitializer {
         return map.keySet().size() > 0;
     }
     
+    public static void openConfigWindow(Gui parent) {
+        MinecraftClient.getInstance().openGui(new ConfigWidget(parent));
+    }
+    
     @Override
     public void clientLoaded() {
-        Registry.ITEM.forEach(this::registerItem);
+        Registry.ITEM.forEach(item -> {
+            if (!item.equals(Items.ENCHANTED_BOOK))
+                registerItem(item);
+        });
         Registry.ENCHANTMENT.forEach(enchantment -> {
             for(int i = enchantment.getMinimumLevel(); i < enchantment.getMaximumLevel(); i++) {
                 Map<Enchantment, Integer> map = new HashMap<>();
@@ -133,13 +145,23 @@ public class ClientHelper implements ClientLoaded, ClientModInitializer {
     
     public void registerItem(Item item) {
         registerItemStack(item.getDefaultStack());
+        DefaultedList<ItemStack> stacks = DefaultedList.create();
+        item.addStacksForDisplay(item.getItemGroup(), stacks);
+        stacks.forEach(this::registerItemStack);
     }
     
     public void registerItemStack(ItemStack stack) {
-        if (!stack.getItem().equals(Items.AIR))
+        if (!stack.getItem().equals(Items.AIR) && !alreadyContain(stack))
             itemList.add(stack);
     }
     
+    private boolean alreadyContain(ItemStack stack) {
+        for(ItemStack itemStack : itemList)
+            if (ItemStack.areEqual(stack, itemStack))
+                return true;
+        return false;
+    }
+    
     @Override
     public void onInitializeClient() {
         this.cheating = false;

+ 18 - 2
src/main/java/me/shedaniel/rei/client/ConfigManager.java → src/main/java/me/shedaniel/rei/client/ConfigHelper.java

@@ -9,13 +9,13 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.nio.file.Files;
 
-public class ConfigManager {
+public class ConfigHelper {
     
     private final File configFile;
     private REIConfig config;
     private boolean craftableOnly;
     
-    public ConfigManager() {
+    public ConfigHelper() {
         this.configFile = new File(FabricLoader.INSTANCE.getConfigDirectory(), "rei.json");
         this.craftableOnly = false;
         try {
@@ -71,4 +71,20 @@ public class ConfigManager {
         return craftableOnly && config.enableCraftableOnlyButton;
     }
     
+    public boolean showCraftableOnlyButton() {
+        return config.enableCraftableOnlyButton;
+    }
+    
+    public void setShowCraftableOnlyButton(boolean enableCraftableOnlyButton) {
+        config.enableCraftableOnlyButton = enableCraftableOnlyButton;
+    }
+    
+    public boolean sideSearchField() {
+        return config.sideSearchField;
+    }
+    
+    public void setSideSearchField(boolean sideSearchField) {
+        config.sideSearchField = sideSearchField;
+    }
+    
 }

+ 1 - 0
src/main/java/me/shedaniel/rei/client/REIConfig.java

@@ -14,5 +14,6 @@ public class REIConfig {
     public REIItemListOrdering itemListOrdering = REIItemListOrdering.REGISTRY;
     public boolean isAscending = true;
     public boolean enableCraftableOnlyButton = true;
+    public boolean sideSearchField = false;
     
 }

+ 19 - 15
src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java

@@ -81,6 +81,12 @@ public class ContainerGuiOverlay extends Gui {
                 ClientHelper.setCheating(!ClientHelper.isCheating());
             }
         });
+        widgets.add(new ButtonWidget(10, 35, 40, 20, I18n.translate("text.rei.config")) {
+            @Override
+            public void onPressed(int button, double mouseX, double mouseY) {
+                ClientHelper.openConfigWindow(containerGui.getContainerGui());
+            }
+        });
         this.widgets.add(new LabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + 10, "") {
             @Override
             public void draw(int mouseX, int mouseY, float partialTicks) {
@@ -89,25 +95,21 @@ public class ContainerGuiOverlay extends Gui {
                 super.draw(mouseX, mouseY, partialTicks);
             }
         });
-//        Rectangle textFieldArea = getTextFieldArea();
-//        this.widgets.add(searchField = new TextFieldWidget(-1, MinecraftClient.getInstance().fontRenderer,
-//                (int) textFieldArea.getX(), (int) textFieldArea.getY(), (int) textFieldArea.getWidth(), (int) textFieldArea.getHeight()) {
-//            @Override
-//            public void addText(String string_1) {
-//                super.addText(string_1);
-//                searchTerm = this.getText();
-//                itemListOverlay.updateList(page, searchTerm);
-//            }
-//        });
         if (GuiHelper.searchField == null)
             GuiHelper.searchField = new TextFieldWidget(0, 0, 0, 0) {
                 @Override
-                public void addText(String string_1) {
-                    super.addText(string_1);
-                    searchTerm = this.getText();
-                    itemListOverlay.updateList(page, searchTerm);
+                public boolean mouseClicked(double double_1, double double_2, int int_1) {
+                    if (isVisible() && getBounds().contains(double_1, double_2) && int_1 == 1) {
+                        setText("");
+                        return true;
+                    }
+                    return super.mouseClicked(double_1, double_2, int_1);
                 }
             };
+        GuiHelper.searchField.setChangedListener(s -> {
+            searchTerm = s;
+            itemListOverlay.updateList(page, searchTerm);
+        });
         GuiHelper.searchField.setBounds(getTextFieldArea());
         this.widgets.add(GuiHelper.searchField);
         GuiHelper.searchField.setText(searchTerm);
@@ -116,6 +118,8 @@ public class ContainerGuiOverlay extends Gui {
     }
     
     private Rectangle getTextFieldArea() {
+        if (RoughlyEnoughItemsCore.getConfigHelper().sideSearchField())
+            return new Rectangle(rectangle.x + 2, window.getScaledHeight() - 22, rectangle.width - 6, 18);
         if (MinecraftClient.getInstance().currentGui instanceof RecipeViewingWidget) {
             RecipeViewingWidget widget = (RecipeViewingWidget) MinecraftClient.getInstance().currentGui;
             return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width, 18);
@@ -128,7 +132,7 @@ public class ContainerGuiOverlay extends Gui {
     }
     
     private Rectangle getItemListArea() {
-        return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - 27);
+        return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - (RoughlyEnoughItemsCore.getConfigHelper().sideSearchField() ? 27 + 22 : 27));
     }
     
     public Rectangle getRectangle() {

+ 7 - 7
src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java

@@ -28,17 +28,17 @@ public abstract class ButtonWidget extends Drawable implements IWidget {
     private boolean pressed;
     private Rectangle bounds;
     
-    public ButtonWidget(int int_2, int int_3, int int_4, int int_5, String string_1) {
+    public ButtonWidget(int x, int y, int width, int height, String text) {
         this.width = 200;
         this.height = 20;
         this.enabled = true;
         this.visible = true;
-        this.x = int_2;
-        this.y = int_3;
-        this.width = int_4;
-        this.height = int_5;
-        this.text = string_1;
-        this.bounds = new Rectangle(x, y, width, height);
+        this.x = x;
+        this.y = y;
+        this.width = width;
+        this.height = height;
+        this.text = text;
+        this.bounds = new Rectangle(x, this.y, this.width, this.height);
     }
     
     public Rectangle getBounds() {

+ 108 - 0
src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java

@@ -0,0 +1,108 @@
+package me.shedaniel.rei.gui.widget;
+
+import com.google.common.collect.Lists;
+import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.GuiEventListener;
+import net.minecraft.client.render.GuiLighting;
+import net.minecraft.client.resource.language.I18n;
+import net.minecraft.client.util.Window;
+
+import java.io.IOException;
+import java.util.List;
+
+public class ConfigWidget extends Gui {
+    
+    private List<IWidget> widgets;
+    private Gui parent;
+    
+    public ConfigWidget(Gui parent) {
+        this.parent = parent;
+        this.widgets = Lists.newArrayList();
+    }
+    
+    @Override
+    public boolean keyPressed(int int_1, int int_2, int int_3) {
+        if (int_1 == 256 && this.doesEscapeKeyClose()) {
+            MinecraftClient.getInstance().openGui(parent);
+            return true;
+        } else {
+            return super.keyPressed(int_1, int_2, int_3);
+        }
+    }
+    
+    @Override
+    protected void onInitialized() {
+        super.onInitialized();
+        widgets.clear();
+        Window window = MinecraftClient.getInstance().window;
+        widgets.add(new ButtonWidget(window.getScaledWidth() / 2 - 20, 30, 40, 20, "") {
+            @Override
+            public void onPressed(int button, double mouseX, double mouseY) {
+                if (button == 0)
+                    RoughlyEnoughItemsCore.getConfigHelper().setSideSearchField(!RoughlyEnoughItemsCore.getConfigHelper().sideSearchField());
+                try {
+                    RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        
+            @Override
+            public void draw(int mouseX, int mouseY, float partialTicks) {
+                text = getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().sideSearchField());
+                String t = I18n.translate("text.rei.centre_searchbox");
+                int width = fontRenderer.getStringWidth(t);
+                fontRenderer.drawWithShadow(t, this.x - width - 10, this.y + (this.height - 8) / 2, -1);
+                super.draw(mouseX, mouseY, partialTicks);
+            }
+        });
+        widgets.add(new ButtonWidget(window.getScaledWidth() / 2 - 20, 60, 40, 20, "") {
+            @Override
+            public void onPressed(int button, double mouseX, double mouseY) {
+                if (button == 0)
+                    RoughlyEnoughItemsCore.getConfigHelper().setShowCraftableOnlyButton(!RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton());
+                try {
+                    RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            
+            @Override
+            public void draw(int mouseX, int mouseY, float partialTicks) {
+                text = getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton());
+                String t = I18n.translate("text.rei.enable_craftable_only");
+                int width = fontRenderer.getStringWidth(t);
+                fontRenderer.drawWithShadow(t, this.x - width - 10, this.y + (this.height - 8) / 2, -1);
+                super.draw(mouseX, mouseY, partialTicks);
+            }
+        });
+    }
+    
+    private String getTrueFalseText(boolean showCraftableOnlyButton) {
+        return String.format("%s%b", showCraftableOnlyButton ? "§a" : "§c", showCraftableOnlyButton);
+    }
+    
+    @Override
+    public void draw(int int_1, int int_2, float float_1) {
+        drawBackground(0);
+        super.draw(int_1, int_2, float_1);
+        widgets.forEach(widget -> {
+            GuiLighting.disable();
+            widget.draw(int_1, int_2, float_1);
+        });
+    }
+    
+    @Override
+    public boolean isPauseScreen() {
+        return false;
+    }
+    
+    @Override
+    public List<? extends GuiEventListener> getEntries() {
+        return widgets;
+    }
+    
+}

+ 5 - 5
src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java

@@ -106,7 +106,7 @@ public class ItemListOverlay extends Drawable implements IWidget {
         List<ItemStack> os = new LinkedList<>(ol), stacks = Lists.newArrayList(), finalStacks = Lists.newArrayList();
         List<ItemGroup> itemGroups = new LinkedList<>(Arrays.asList(ItemGroup.GROUPS));
         itemGroups.add(null);
-        REIItemListOrdering ordering = RoughlyEnoughItemsCore.getConfigManager().getItemListOrdering();
+        REIItemListOrdering ordering = RoughlyEnoughItemsCore.getConfigHelper().getItemListOrdering();
         if (ordering != REIItemListOrdering.REGISTRY)
             Collections.sort(os, (itemStack, t1) -> {
                 if (ordering.equals(REIItemListOrdering.NAME))
@@ -115,7 +115,7 @@ public class ItemListOverlay extends Drawable implements IWidget {
                     return itemGroups.indexOf(itemStack.getItem().getItemGroup()) - itemGroups.indexOf(t1.getItem().getItemGroup());
                 return 0;
             });
-        if (!RoughlyEnoughItemsCore.getConfigManager().isAscending())
+        if (!RoughlyEnoughItemsCore.getConfigHelper().isAscending())
             Collections.reverse(os);
         Arrays.stream(searchTerm.split("\\|")).forEachOrdered(s -> {
             List<SearchArgument> arguments = new ArrayList<>();
@@ -135,14 +135,14 @@ public class ItemListOverlay extends Drawable implements IWidget {
                 arguments.add(new SearchArgument(SearchArgument.ArgumentType.TEXT, s, true));
             os.stream().filter(itemStack -> filterItem(itemStack, arguments)).forEachOrdered(stacks::add);
         });
-        List<ItemStack> workingItems = RoughlyEnoughItemsCore.getConfigManager().craftableOnly() && inventoryItems.size() > 0 ? new ArrayList<>() : new LinkedList<>(ol);
-        if (RoughlyEnoughItemsCore.getConfigManager().craftableOnly()) {
+        List<ItemStack> workingItems = RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() && inventoryItems.size() > 0 ? new ArrayList<>() : new LinkedList<>(ol);
+        if (RoughlyEnoughItemsCore.getConfigHelper().craftableOnly()) {
             RecipeHelper.findCraftableByItems(inventoryItems).forEach(workingItems::add);
             workingItems.addAll(inventoryItems);
         }
         final List<ItemStack> finalWorkingItems = workingItems;
         finalStacks.addAll(stacks.stream().filter(itemStack -> {
-            if (!RoughlyEnoughItemsCore.getConfigManager().craftableOnly())
+            if (!RoughlyEnoughItemsCore.getConfigHelper().craftableOnly())
                 return true;
             for(ItemStack workingItem : finalWorkingItems)
                 if (itemStack.isEqualIgnoreTags(workingItem))

+ 5 - 0
src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java

@@ -73,6 +73,11 @@ public class RecipeViewingWidget extends Gui {
         return super.keyPressed(int_1, int_2, int_3);
     }
     
+    @Override
+    public boolean isPauseScreen() {
+        return false;
+    }
+    
     @Override
     public void onClosed() {
         GuiHelper.resetOverlay();

+ 11 - 7
src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java

@@ -49,13 +49,6 @@ public class TextFieldWidget extends Drawable implements IWidget {
         this(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
     }
     
-    public void setBounds(Rectangle rectangle) {
-        this.x = rectangle.x;
-        this.y = rectangle.y;
-        this.width = rectangle.width;
-        this.height = rectangle.height;
-    }
-    
     public TextFieldWidget(int x, int y, int width, int height) {
         this.text = "";
         this.maxLength = 32;
@@ -76,6 +69,17 @@ public class TextFieldWidget extends Drawable implements IWidget {
         this.height = height;
     }
     
+    public Rectangle getBounds() {
+        return new Rectangle(x, y, width, height);
+    }
+    
+    public void setBounds(Rectangle rectangle) {
+        this.x = rectangle.x;
+        this.y = rectangle.y;
+        this.width = rectangle.width;
+        this.height = rectangle.height;
+    }
+    
     public void setChangedListener(Consumer<String> biConsumer_1) {
         this.changedListener = biConsumer_1;
     }

+ 68 - 0
src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java

@@ -0,0 +1,68 @@
+package me.shedaniel.rei.mixin;
+
+import com.google.common.collect.Lists;
+import me.shedaniel.rei.plugin.BrewingRecipe;
+import me.shedaniel.rei.plugin.DefaultBrewingDisplay;
+import me.shedaniel.rei.plugin.DefaultPlugin;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemProvider;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.PotionItem;
+import net.minecraft.potion.Potion;
+import net.minecraft.potion.PotionUtil;
+import net.minecraft.recipe.BrewingRecipeRegistry;
+import net.minecraft.recipe.Ingredient;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import java.util.List;
+
+@Mixin(BrewingRecipeRegistry.class)
+public class MixinBrewingRecipeRegistry {
+    
+    private static final List<BrewingRecipe> ITEM_RECIPES = Lists.newArrayList();
+    private static final List<Potion> REGISTERED_POTION_TYPES = Lists.newArrayList();
+    private static final List<Ingredient> POTION_TYPES = Lists.newArrayList();
+    
+    @Inject(method = "method_8080", at = @At("RETURN"))
+    private static void method_8080(Item item_1, CallbackInfo ci) {
+        if (!(item_1 instanceof PotionItem)) {
+        } else {
+            POTION_TYPES.add(Ingredient.ofItems(new ItemProvider[]{item_1}));
+        }
+    }
+    
+    @Inject(method = "method_8071", at = @At("RETURN"))
+    private static void method_8071(Item item_1, Item item_2, Item item_3, CallbackInfo ci) {
+        if (!(item_1 instanceof PotionItem)) {
+        } else if (!(item_3 instanceof PotionItem)) {
+        } else {
+            ITEM_RECIPES.add(new BrewingRecipe(item_1, Ingredient.ofItems(new ItemProvider[]{item_2}), item_3));
+        }
+    }
+    
+    @Inject(method = "registerPotionRecipe", at = @At("RETURN"))
+    private static void registerPotionRecipe(Potion potion_1, Item item_1, Potion potion_2, CallbackInfo ci) {
+        if (!REGISTERED_POTION_TYPES.contains(potion_1))
+            registerPotionType(potion_1);
+        if (!REGISTERED_POTION_TYPES.contains(potion_2))
+            registerPotionType(potion_2);
+        POTION_TYPES.forEach(ingredient -> {
+            for(ItemStack stack : ingredient.getStackArray()) {
+                DefaultPlugin.registerBrewingDisplay(new DefaultBrewingDisplay(PotionUtil.setPotion(stack.copy(), potion_1), Ingredient.ofItems(new ItemProvider[]{item_1}),
+                        PotionUtil.setPotion(stack.copy(), potion_2)));
+            }
+        });
+    }
+    
+    private static void registerPotionType(Potion potion) {
+        REGISTERED_POTION_TYPES.add(potion);
+        ITEM_RECIPES.forEach(recipe -> {
+            DefaultPlugin.registerBrewingDisplay(new DefaultBrewingDisplay(PotionUtil.setPotion(recipe.input.getDefaultStack(), potion), recipe.ingredient,
+                    PotionUtil.setPotion(recipe.output.getDefaultStack(), potion)));
+        });
+    }
+    
+}

+ 17 - 0
src/main/java/me/shedaniel/rei/plugin/BrewingRecipe.java

@@ -0,0 +1,17 @@
+package me.shedaniel.rei.plugin;
+
+import net.minecraft.item.Item;
+import net.minecraft.recipe.Ingredient;
+
+public class BrewingRecipe {
+    
+    public final Item input;
+    public final Ingredient ingredient;
+    public final Item output;
+    
+    public BrewingRecipe(Item object_1, Ingredient ingredient_1, Item object_2) {
+        this.input = object_1;
+        this.ingredient = ingredient_1;
+        this.output = object_2;
+    }
+}

+ 66 - 0
src/main/java/me/shedaniel/rei/plugin/DefaultBrewingCategory.java

@@ -0,0 +1,66 @@
+package me.shedaniel.rei.plugin;
+
+import com.mojang.blaze3d.platform.GlStateManager;
+import me.shedaniel.rei.api.IRecipeCategory;
+import me.shedaniel.rei.gui.widget.IWidget;
+import me.shedaniel.rei.gui.widget.ItemSlotWidget;
+import me.shedaniel.rei.gui.widget.RecipeBaseWidget;
+import me.shedaniel.rei.listeners.IMixinContainerGui;
+import net.minecraft.block.Blocks;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.render.GuiLighting;
+import net.minecraft.client.resource.language.I18n;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.Items;
+import net.minecraft.util.Identifier;
+import net.minecraft.util.math.MathHelper;
+
+import java.awt.*;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+public class DefaultBrewingCategory implements IRecipeCategory<DefaultBrewingDisplay> {
+    
+    private static final Identifier DISPLAY_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/display.png");
+    
+    @Override
+    public Identifier getIdentifier() {
+        return DefaultPlugin.BREWING;
+    }
+    
+    @Override
+    public ItemStack getCategoryIcon() {
+        return new ItemStack(Blocks.BREWING_STAND);
+    }
+    
+    @Override
+    public String getCategoryName() {
+        return I18n.translate("category.rei.brewing");
+    }
+    
+    @Override
+    public List<IWidget> setupDisplay(IMixinContainerGui containerGui, DefaultBrewingDisplay recipeDisplay, Rectangle bounds) {
+        Point startPoint = new Point((int) bounds.getCenterX() - 52, (int) bounds.getCenterY() - 29);
+        List<IWidget> widgets = new LinkedList<>(Arrays.asList(new RecipeBaseWidget(bounds) {
+            @Override
+            public void draw(int mouseX, int mouseY, float partialTicks) {
+                super.draw(mouseX, mouseY, partialTicks);
+                GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
+                GuiLighting.disable();
+                MinecraftClient.getInstance().getTextureManager().bindTexture(DISPLAY_TEXTURE);
+                drawTexturedRect(startPoint.x, startPoint.y, 0, 108, 103, 59);
+                int width = MathHelper.ceil((System.currentTimeMillis() / 250 % 18d) / 1f);
+                drawTexturedRect(startPoint.x + 44, startPoint.y + 28, 103, 163, width, 4);
+            }
+        }));
+        widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 1, Arrays.asList(new ItemStack(Items.BLAZE_POWDER)), false, true, containerGui, true));
+        widgets.add(new ItemSlotWidget(startPoint.x + 63, startPoint.y + 1, recipeDisplay.getInput().get(0), false, true, containerGui, true));
+        widgets.add(new ItemSlotWidget(startPoint.x + 40, startPoint.y + 1, recipeDisplay.getInput().get(1), false, true, containerGui, true));
+        widgets.add(new ItemSlotWidget(startPoint.x + 40, startPoint.y + 35, recipeDisplay.getOutput(0), false, true, containerGui, true));
+        widgets.add(new ItemSlotWidget(startPoint.x + 63, startPoint.y + 42, recipeDisplay.getOutput(1), false, true, containerGui, true));
+        widgets.add(new ItemSlotWidget(startPoint.x + 86, startPoint.y + 35, recipeDisplay.getOutput(2), false, true, containerGui, true));
+        return widgets;
+    }
+    
+}

+ 54 - 0
src/main/java/me/shedaniel/rei/plugin/DefaultBrewingDisplay.java

@@ -0,0 +1,54 @@
+package me.shedaniel.rei.plugin;
+
+import me.shedaniel.rei.api.IRecipeDisplay;
+import net.minecraft.block.Blocks;
+import net.minecraft.item.ItemStack;
+import net.minecraft.recipe.Ingredient;
+import net.minecraft.recipe.Recipe;
+import net.minecraft.util.Identifier;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class DefaultBrewingDisplay implements IRecipeDisplay {
+    
+    private ItemStack input, output;
+    private Ingredient reactant;
+    
+    public DefaultBrewingDisplay(ItemStack input, Ingredient reactant, ItemStack output) {
+        this.input = input;
+        this.reactant = reactant;
+        this.output = output;
+    }
+    
+    @Override
+    public Recipe getRecipe() {
+        return null;
+    }
+    
+    @Override
+    public List<List<ItemStack>> getInput() {
+        return Arrays.asList(Arrays.asList(input), Arrays.asList(reactant.getStackArray()));
+    }
+    
+    @Override
+    public List<ItemStack> getOutput() {
+        return Arrays.asList(output);
+    }
+    
+    @Override
+    public Identifier getRecipeCategory() {
+        return DefaultPlugin.BREWING;
+    }
+    
+    public List<ItemStack> getOutput(int slot) {
+        List<ItemStack> stack = new ArrayList<>();
+        for(int i = 0; i < slot * 2; i++)
+            stack.add(new ItemStack(Blocks.AIR));
+        for(int i = 0; i < 6 - slot * 2; i++)
+            stack.addAll(getOutput());
+        return stack;
+    }
+    
+}

+ 14 - 0
src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java

@@ -1,5 +1,7 @@
 package me.shedaniel.rei.plugin;
 
+import com.google.common.collect.Lists;
+import me.shedaniel.rei.RoughlyEnoughItemsCore;
 import me.shedaniel.rei.api.IRecipePlugin;
 import me.shedaniel.rei.client.RecipeHelper;
 import net.minecraft.recipe.Recipe;
@@ -10,12 +12,21 @@ import net.minecraft.recipe.smelting.SmeltingRecipe;
 import net.minecraft.recipe.smelting.SmokingRecipe;
 import net.minecraft.util.Identifier;
 
+import java.util.List;
+
 public class DefaultPlugin implements IRecipePlugin {
     
     static final Identifier CRAFTING = new Identifier("roughlyenoughitems", "plugins/crafting");
     static final Identifier SMELTING = new Identifier("roughlyenoughitems", "plugins/smelting");
     static final Identifier SMOKING = new Identifier("roughlyenoughitems", "plugins/smoking");
     static final Identifier BLASTING = new Identifier("roughlyenoughitems", "plugins/blasting");
+    static final Identifier BREWING = new Identifier("roughlyenoughitems", "plugins/brewing");
+    
+    static final List<DefaultBrewingDisplay> BREWING_DISPLAYS = Lists.newArrayList();
+    
+    public static void registerBrewingDisplay(DefaultBrewingDisplay display) {
+        BREWING_DISPLAYS.add(display);
+    }
     
     @Override
     public void registerPluginCategories() {
@@ -23,6 +34,7 @@ public class DefaultPlugin implements IRecipePlugin {
         RecipeHelper.registerCategory(new DefaultSmeltingCategory());
         RecipeHelper.registerCategory(new DefaultSmokingCategory());
         RecipeHelper.registerCategory(new DefaultBlastingCategory());
+        RecipeHelper.registerCategory(new DefaultBrewingCategory());
     }
     
     @Override
@@ -38,6 +50,8 @@ public class DefaultPlugin implements IRecipePlugin {
                 RecipeHelper.registerRecipe(SMOKING, new DefaultSmokingDisplay((SmokingRecipe) value));
             else if (value instanceof BlastingRecipe)
                 RecipeHelper.registerRecipe(BLASTING, new DefaultBlastingDisplay((BlastingRecipe) value));
+        BREWING_DISPLAYS.forEach(display -> RecipeHelper.registerRecipe(BREWING, display));
+        RoughlyEnoughItemsCore.LOGGER.info("bad lol " + BREWING_DISPLAYS.size());
     }
     
 }

+ 2 - 4
src/main/resources/assets/roughlyenoughitems/lang/en_us.json

@@ -17,8 +17,7 @@
   "category.rei.brewing.result": "§eResulted Potion",
   "text.rei.config": "Config",
   "text.rei.listeningkey": "Listening Key",
-  "text.rei.centre_searchbox": "Center Search Box: %s%b",
-  "text.rei.centre_searchbox.tooltip": "Please restart Minecraft after editing\nthis config to apply the changes",
+  "text.rei.centre_searchbox": "Right Search Box: ",
   "text.rei.cheat_items": "Given [%s] x%d to %s.",
   "text.rei.failed_cheat_items": "§cFailed to give items.",
   "text.rei.list_ordering": "Item List Ordering",
@@ -30,8 +29,7 @@
   "ordering.rei.item_groups": "Item Groups",
   "text.auto_craft.wrong_gui": "§cCan't auto craft in this inventory!",
   "text.auto_craft.crafting.too_small": "§cThis inventory is too small!",
-  "text.rei.enable_craftable_only.button": "Craftable Only: %s%b",
-  "text.rei.enable_craftable_only.tooltip": "Please resize the window after editing\nthis config to apply the changes",
+  "text.rei.enable_craftable_only": "Enable Craftable Only: ",
   "text.rei.showing_craftable": "Showing Craftable",
   "text.rei.showing_all": "Showing All",
   "text.rei.delete_items": "§cDelete Item"

BIN
src/main/resources/assets/roughlyenoughitems/textures/gui/display.png


+ 1 - 1
src/main/resources/fabric.mod.json

@@ -2,7 +2,7 @@
   "id": "roughlyenoughitems",
   "name": "RoughlyEnoughItems",
   "description": "To allow players to view items and recipes.",
-  "version": "2.0.0.32",
+  "version": "2.0.0.33",
   "side": "client",
   "authors": [
     "Danielshe"

+ 2 - 1
src/main/resources/roughlyenoughitems.client.json

@@ -7,7 +7,8 @@
     "MixinClientPlayNetworkHandler",
     "MixinPlayerInventoryGui",
     "MixinCraftingTableGui",
-    "MixinCreativePlayerInventoryGui"
+    "MixinCreativePlayerInventoryGui",
+    "MixinBrewingRecipeRegistry"
   ],
   "injectors": {
     "defaultRequire": 1