diff options
Diffstat (limited to 'src/main/java/me')
3 files changed, 53 insertions, 29 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 64c74f4fb..efca3aa36 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/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); }); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java index 4134ad510..5e9cb4dc3 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java +++ b/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); + } } } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java index 59708ad4b..9e1509880 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java +++ b/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()); |
