Browse Source

Resizable Recipe Base, Better Language Files, Trying to fix recipes not being loaded

Unknown 6 years ago
parent
commit
ced2b8eea0

+ 2 - 2
build.gradle

@@ -6,7 +6,7 @@ sourceCompatibility = 1.8
 targetCompatibility = 1.8
 
 archivesBaseName = "RoughlyEnoughItems"
-version = "2.1.0.41"
+version = "2.1.0.42"
 
 def minecraftVersion = "19w03c"
 def yarnVersion = "19w03c.4"
@@ -25,7 +25,7 @@ processResources {
 dependencies {
 	minecraft "com.mojang:minecraft:${minecraftVersion}"
 	mappings "net.fabricmc:yarn:${yarnVersion}"
-	modCompile "net.fabricmc:fabric-loader:0.3.2.96"
+	modCompile "net.fabricmc:fabric-loader:0.3.3.100"
 
 	// Fabric API. This is technically optional, but you probably want it anyway.
 	modCompile "net.fabricmc:fabric:${fabricVersion}"

+ 37 - 24
src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java

@@ -15,18 +15,22 @@ import net.fabricmc.api.ModInitializer;
 import net.fabricmc.fabric.networking.CustomPayloadPacketRegistry;
 import net.fabricmc.loader.FabricLoader;
 import net.fabricmc.loader.ModContainer;
+import net.minecraft.client.resource.language.I18n;
 import net.minecraft.item.ItemStack;
 import net.minecraft.server.network.ServerPlayerEntity;
 import net.minecraft.sortme.ChatMessageType;
+import net.minecraft.text.StringTextComponent;
 import net.minecraft.text.TranslatableTextComponent;
 import net.minecraft.util.Identifier;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
@@ -103,41 +107,46 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
     
     private void discoverPlugins() {
         Collection<ModContainer> modContainers = FabricLoader.INSTANCE.getModContainers();
-        List<REIPluginInfo> pluginInfos = Lists.newArrayList();
+        List<REIPluginInfo> pluginInfoList = Lists.newArrayList();
         JsonParser parser = new JsonParser();
         modContainers.forEach(modContainer -> {
+            InputStream inputStream = null;
             if (modContainer.getOriginFile().isFile())
                 try (JarFile file = new JarFile(modContainer.getOriginFile())) {
-                    ZipEntry entry = file.getEntry("plugins" + File.separator + "rei.plugin.json");
-                    if (entry != null) {
-                        InputStream in = file.getInputStream(entry);
-                        JsonElement jsonElement = parser.parse(new InputStreamReader(in));
-                        if (jsonElement != null && jsonElement.isJsonObject()) {
-                            REIPluginInfo info = REIPluginInfo.GSON.fromJson(jsonElement, REIPluginInfo.class);
-                            if (info != null)
-                                pluginInfos.add(info);
-                        }
-                    }
+                    ZipEntry entry = file.getEntry("plugins" + File.separatorChar + "rei.plugin.json");
+                    if (entry != null)
+                        inputStream = file.getInputStream(entry);
                 } catch (Exception e) {
-                    RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load REI plugin info from " + modContainer.getInfo().getId() + " when it should can. (" + e.getLocalizedMessage() + ")");
+                    RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load plugin file from " + modContainer.getInfo().getId() + ". (" + e.getLocalizedMessage() + ")");
                 }
             else if (modContainer.getOriginFile().isDirectory()) {
-                File modInfo = new File(modContainer.getOriginFile(), "plugins" + File.separator + "rei.plugin.json");
+                File modInfo = new File(modContainer.getOriginFile(), "plugins" + File.separatorChar + "rei.plugin.json");
                 if (modInfo.exists())
                     try {
-                        InputStream in = Files.newInputStream(modInfo.toPath());
-                        JsonElement jsonElement = parser.parse(new InputStreamReader(in));
-                        if (jsonElement != null && jsonElement.isJsonObject()) {
-                            REIPluginInfo info = REIPluginInfo.GSON.fromJson(jsonElement, REIPluginInfo.class);
-                            if (info != null)
-                                pluginInfos.add(info);
-                        }
+                        inputStream = Files.newInputStream(modInfo.toPath(), StandardOpenOption.READ);
                     } catch (Exception e) {
-                        RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load REI plugin info from " + modContainer.getInfo().getId() + " when it should can. (" + e.getLocalizedMessage() + ")");
+                        RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load plugin file from " + modContainer.getInfo().getId() + ". (" + e.getLocalizedMessage() + ")");
                     }
             }
+            if (inputStream != null)
+                try {
+                    JsonElement jsonElement = parser.parse(new InputStreamReader(inputStream));
+                    if (jsonElement != null && jsonElement.isJsonObject()) {
+                        REIPluginInfo info = REIPluginInfo.GSON.fromJson(jsonElement, REIPluginInfo.class);
+                        if (info != null)
+                            pluginInfoList.add(info);
+                    }
+                } catch (Exception e) {
+                    RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load REI plugin info from " + modContainer.getInfo().getId() + ". (" + e.getLocalizedMessage() + ")");
+                } finally {
+                    try {
+                        inputStream.close();
+                    } catch (IOException e) {
+                        RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to close input stream from " + modContainer.getInfo().getId() + ". (" + e.getLocalizedMessage() + ")");
+                    }
+                }
         });
-        pluginInfos.stream().forEachOrdered(reiPluginInfo -> {
+        pluginInfoList.stream().forEachOrdered(reiPluginInfo -> {
             reiPluginInfo.getPlugins().forEach(reiPlugin -> {
                 try {
                     Identifier identifier = new Identifier(reiPlugin.getIdentifier());
@@ -146,7 +155,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
                     RoughlyEnoughItemsCore.registerPlugin(identifier, plugin);
                     RoughlyEnoughItemsCore.LOGGER.info("REI: Registered REI plugin: " + reiPlugin.getIdentifier());
                 } catch (Exception e) {
-                    RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load REI plugin: " + reiPlugin.getIdentifier() + " (" + e.getLocalizedMessage() + ")");
+                    RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to register REI plugin: " + reiPlugin.getIdentifier() + ". (" + e.getLocalizedMessage() + ")");
                 }
             });
         });
@@ -162,7 +171,11 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali
             ServerPlayerEntity player = (ServerPlayerEntity) packetContext.getPlayer();
             ItemStack stack = packetByteBuf.readItemStack();
             if (player.inventory.insertStack(stack.copy()))
-                player.sendChatMessage(new TranslatableTextComponent("text.rei.cheat_items", stack.getDisplayName().getFormattedText(), stack.getAmount(), player.getEntityName()), ChatMessageType.SYSTEM);
+                player.sendChatMessage(new StringTextComponent(I18n.translate("text.rei.cheat_items")
+                        .replaceAll("\\{item_name}", stack.copy().getDisplayName().getFormattedText())
+                        .replaceAll("\\{item_count}", stack.copy().getAmount() + "")
+                        .replaceAll("\\{player_name}", player.getEntityName())
+                ), ChatMessageType.SYSTEM);
             else
                 player.sendChatMessage(new TranslatableTextComponent("text.rei.failed_cheat_items"), ChatMessageType.SYSTEM);
         });

+ 12 - 1
src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java

@@ -1,10 +1,12 @@
 package me.shedaniel.rei.gui.widget;
 
 import com.mojang.blaze3d.platform.GlStateManager;
+import me.shedaniel.rei.RoughlyEnoughItemsCore;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.gui.Drawable;
 import net.minecraft.client.render.GuiLighting;
 import net.minecraft.util.Identifier;
+import net.minecraft.util.math.MathHelper;
 
 import java.awt.*;
 import java.util.ArrayList;
@@ -30,7 +32,16 @@ public class RecipeBaseWidget extends Drawable implements IWidget {
         GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
         GuiLighting.disable();
         MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
-        drawTexturedRect(bounds.x, bounds.y, 106, 190, bounds.width, bounds.height);
+        drawTexturedRect(bounds.x, bounds.y, 106, 190, bounds.width / 2, bounds.height / 2);
+        drawTexturedRect(bounds.x + bounds.width / 2, bounds.y, 256 - bounds.width / 2, 190, bounds.width / 2, bounds.height / 2);
+        drawTexturedRect(bounds.x, bounds.y + bounds.height / 2, 106, 190 + 66 - bounds.height / 2, bounds.width / 2, bounds.height / 2);
+        drawTexturedRect(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, 256 - bounds.width / 2, 190 + 66 - bounds.height / 2, bounds.width / 2, bounds.height / 2);
+        if (bounds.height > 40)
+            for(int i = 20; i < bounds.height - 20; i += MathHelper.clamp(20, 0, bounds.height - 20 - i)) {
+                int height = MathHelper.clamp(20, 0, bounds.height - 20 - i);
+                drawTexturedRect(bounds.x, bounds.y + i, 106, 230, bounds.width / 2, height);
+                drawTexturedRect(bounds.x + bounds.width / 2, bounds.y + i, 256 - bounds.width / 2, 210, bounds.width / 2, height);
+            }
     }
     
 }

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

@@ -190,10 +190,10 @@ public class RecipeViewingWidget extends Gui {
         final SpeedCraftFunctional functional = functional0[0];
         if (page * getRecipesPerPage() < categoriesMap.get(selectedCategory).size()) {
             IRecipeDisplay topDisplay = categoriesMap.get(selectedCategory).get(page * getRecipesPerPage());
-            widgets.addAll(selectedCategory.setupDisplay(getParent(), topDisplay, new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 40, 150, selectedCategory.usesFullPage() ? 118 : 66)));
+            widgets.addAll(selectedCategory.setupDisplay(getParent(), topDisplay, new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 40, 150, selectedCategory.usesFullPage() ? 140 : 66)));
             if (supplier != null) {
                 ButtonWidget btn;
-                widgets.add(btn = new ButtonWidget(supplier.get(new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 40, 150, selectedCategory.usesFullPage() ? 118 : 66)), "+") {
+                widgets.add(btn = new ButtonWidget(supplier.get(new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 40, 150, selectedCategory.usesFullPage() ? 140 : 66)), "+") {
                     @Override
                     public void onPressed(int button, double mouseX, double mouseY) {
                         MinecraftClient.getInstance().openGui(parent.getContainerGui());
@@ -214,10 +214,10 @@ public class RecipeViewingWidget extends Gui {
             }
             if (!selectedCategory.usesFullPage() && page * getRecipesPerPage() + 1 < categoriesMap.get(selectedCategory).size()) {
                 IRecipeDisplay middleDisplay = categoriesMap.get(selectedCategory).get(page * getRecipesPerPage() + 1);
-                widgets.addAll(selectedCategory.setupDisplay(getParent(), middleDisplay, new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 108, 150, 66)));
+                widgets.addAll(selectedCategory.setupDisplay(getParent(), middleDisplay, new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 113, 150, 66)));
                 if (supplier != null) {
                     ButtonWidget btn;
-                    widgets.add(btn = new ButtonWidget(supplier.get(new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 108, 150, 66)), "+") {
+                    widgets.add(btn = new ButtonWidget(supplier.get(new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 113, 150, 66)), "+") {
                         @Override
                         public void onPressed(int button, double mouseX, double mouseY) {
                             MinecraftClient.getInstance().openGui(parent.getContainerGui());

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

@@ -16,7 +16,7 @@
   "category.rei.brewing.result": "§eResulted Potion",
   "text.rei.config": "Config",
   "text.rei.centre_searchbox": "Right Search Box: ",
-  "text.rei.cheat_items": "Given [%s] x%d to %s.",
+  "text.rei.cheat_items": "Given [{item_name}] x{item_count} to {player_name}.",
   "text.rei.failed_cheat_items": "§cFailed to give items.",
   "text.rei.list_ordering": "Item List Ordering",
   "text.rei.list_ordering_button": "%s [%s]",

+ 2 - 0
src/main/resources/assets/roughlyenoughitems/lang/zh_cn.json

@@ -16,6 +16,8 @@
   "category.rei.brewing.result": "§e输出药水",
   "text.rei.config": "设置",
   "text.rei.centre_searchbox": "右置搜索栏: ",
+  "text.rei.cheat_items": "已将 {item_count} 个 [{item_name}] 给予 {player_name}",
+  "text.rei.failed_cheat_items": "§c不能给予物品.",
   "text.rei.list_ordering": "物品清单排序",
   "text.rei.list_ordering_button": "%s [%s]",
   "ordering.rei.ascending": "顺序",

+ 2 - 0
src/main/resources/assets/roughlyenoughitems/lang/zh_tw.json

@@ -16,6 +16,8 @@
   "category.rei.brewing.result": "§e輸出藥水",
   "text.rei.config": "設置",
   "text.rei.centre_searchbox": "右置搜索欄: ",
+  "text.rei.cheat_items": "已將 {item_count} 個 [{item_name}] 給予 {player_name}",
+  "text.rei.failed_cheat_items": "§c不能給予物品.",
   "text.rei.list_ordering": "物品清單排序",
   "text.rei.list_ordering_button": "%s [%s]",
   "ordering.rei.ascending": "順序",