diff options
| author | Daniel She <shekwancheung0528@gmail.com> | 2019-02-25 21:18:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-25 21:18:26 +0800 |
| commit | 9e55b44b710f38c63a4bfd17d0b07318d5c68535 (patch) | |
| tree | a2cc0c519b4327028d7b8f544ba5171fff2d8dc1 /src/main/java | |
| parent | b7e018527db2e9cae2db4226f6af9fc34054c964 (diff) | |
| download | RoughlyEnoughItems-9e55b44b710f38c63a4bfd17d0b07318d5c68535.tar.gz RoughlyEnoughItems-9e55b44b710f38c63a4bfd17d0b07318d5c68535.tar.bz2 RoughlyEnoughItems-9e55b44b710f38c63a4bfd17d0b07318d5c68535.zip | |
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
Diffstat (limited to 'src/main/java')
46 files changed, 1538 insertions, 458 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index faa647b3f..604d22f2e 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -3,6 +3,7 @@ package me.shedaniel.rei; import com.google.common.collect.Maps; import me.shedaniel.rei.api.IItemRegisterer; import me.shedaniel.rei.api.IPluginDisabler; +import me.shedaniel.rei.api.IRecipeHelper; import me.shedaniel.rei.api.IRecipePlugin; import me.shedaniel.rei.client.ConfigHelper; import me.shedaniel.rei.client.GuiHelper; @@ -19,7 +20,6 @@ import net.fabricmc.loader.FabricLoader; 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; @@ -29,6 +29,7 @@ import org.apache.logging.log4j.Logger; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitializer { @@ -41,7 +42,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali private static final Map<Identifier, IRecipePlugin> plugins = Maps.newHashMap(); private static ConfigHelper configHelper; - public static RecipeHelper getRecipeHelper() { + public static IRecipeHelper getRecipeHelper() { return RECIPE_HELPER; } @@ -68,11 +69,11 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali return new LinkedList<>(plugins.values()); } - public static Identifier getPluginIdentifier(IRecipePlugin plugin) { + public static Optional<Identifier> getPluginIdentifier(IRecipePlugin plugin) { for(Identifier identifier : plugins.keySet()) - if (plugins.get(identifier).equals(plugin)) - return identifier; - return null; + if (identifier != null && plugins.get(identifier).equals(plugin)) + return Optional.of(identifier); + return Optional.empty(); } @SuppressWarnings("deprecation") @@ -87,7 +88,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali } ClientTickCallback.EVENT.register(GuiHelper::onTick); - if (getConfigHelper().checkUpdates()) + if (getConfigHelper().getConfig().checkUpdates) ClientTickCallback.EVENT.register(UpdateChecker::onTick); new UpdateChecker().onInitializeClient(); @@ -108,9 +109,9 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali ServerPlayerEntity player = (ServerPlayerEntity) packetContext.getPlayer(); ItemStack stack = packetByteBuf.readItemStack(); if (player.inventory.insertStack(stack.copy())) - 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); + player.addChatMessage(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())), false); else - player.sendChatMessage(new TranslatableTextComponent("text.rei.failed_cheat_items"), ChatMessageType.SYSTEM); + player.addChatMessage(new TranslatableTextComponent("text.rei.failed_cheat_items"), false); }); } diff --git a/src/main/java/me/shedaniel/rei/api/IDisplaySettings.java b/src/main/java/me/shedaniel/rei/api/IDisplaySettings.java new file mode 100644 index 000000000..1cb315fb2 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/IDisplaySettings.java @@ -0,0 +1,11 @@ +package me.shedaniel.rei.api; + +public interface IDisplaySettings<T extends IRecipeDisplay> { + + public int getDisplayHeight(IRecipeCategory category); + + public int getDisplayWidth(IRecipeCategory category, T display); + + public int getMaximumRecipePerPage(IRecipeCategory category); + +} diff --git a/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java b/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java index 123fa20df..9665e6a89 100644 --- a/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/IRecipeCategory.java @@ -1,12 +1,9 @@ package me.shedaniel.rei.api; -import com.mojang.blaze3d.platform.GlStateManager; +import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.widget.IWidget; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; -import me.shedaniel.rei.gui.widget.RecipeViewingWidgetScreen; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.render.GuiLighting; +import net.minecraft.client.gui.DrawableHelper; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; @@ -24,21 +21,45 @@ public interface IRecipeCategory<T extends IRecipeDisplay> { public String getCategoryName(); - default public boolean usesFullPage() { - return false; - } - default public List<IWidget> setupDisplay(Supplier<T> recipeDisplaySupplier, Rectangle bounds) { return Arrays.asList(new RecipeBaseWidget(bounds)); } - default public void drawCategoryBackground(Rectangle bounds) { - GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); - GuiLighting.disable(); - MinecraftClient.getInstance().getTextureManager().bindTexture(RecipeViewingWidgetScreen.CHEST_GUI_TEXTURE); - new Drawable() { - - }.drawTexturedRect((int) bounds.getX(), (int) bounds.getY(), 0, 0, (int) bounds.getWidth(), (int) bounds.getHeight()); + default public void drawCategoryBackground(Rectangle bounds, int mouseX, int mouseY, float delta) { + new RecipeBaseWidget(bounds).draw(mouseX, mouseY, delta); + DrawableHelper.drawRect(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, RecipeViewingScreen.SUB_COLOR.getRGB()); + DrawableHelper.drawRect(bounds.x + 17, bounds.y + 21, bounds.x + bounds.width - 17, bounds.y + 33, RecipeViewingScreen.SUB_COLOR.getRGB()); + } + + default public IDisplaySettings getDisplaySettings() { + return new IDisplaySettings<T>() { + @Override + public int getDisplayHeight(IRecipeCategory category) { + return 66; + } + + @Override + public int getDisplayWidth(IRecipeCategory category, T display) { + return 150; + } + + @Override + public int getMaximumRecipePerPage(IRecipeCategory category) { + return 99; + } + }; + } + + default public int getDisplayHeight() { + return getDisplaySettings().getDisplayHeight(this); + } + + default public int getDisplayWidth(T display) { + return getDisplaySettings().getDisplayWidth(this, display); + } + + default public int getMaximumRecipePerPage() { + return getDisplaySettings().getMaximumRecipePerPage(this); } default public boolean checkTags() { diff --git a/src/main/java/me/shedaniel/rei/api/IRecipeDisplay.java b/src/main/java/me/shedaniel/rei/api/IRecipeDisplay.java index 1a19b21c5..9d390385c 100644 --- a/src/main/java/me/shedaniel/rei/api/IRecipeDisplay.java +++ b/src/main/java/me/shedaniel/rei/api/IRecipeDisplay.java @@ -6,10 +6,11 @@ import net.minecraft.recipe.Recipe; import net.minecraft.util.Identifier; import java.util.List; +import java.util.Optional; public interface IRecipeDisplay<T extends Recipe> { - public abstract T getRecipe(); + public abstract Optional<T> getRecipe(); public List<List<ItemStack>> getInput(); diff --git a/src/main/java/me/shedaniel/rei/api/IRecipeHelper.java b/src/main/java/me/shedaniel/rei/api/IRecipeHelper.java new file mode 100644 index 000000000..8d9651f32 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/IRecipeHelper.java @@ -0,0 +1,44 @@ +package me.shedaniel.rei.api; + +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.RecipeManager; +import net.minecraft.util.Identifier; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public interface IRecipeHelper { + + public static IRecipeHelper getInstance() { + return RoughlyEnoughItemsCore.getRecipeHelper(); + } + + public int getRecipeCount(); + + public List<ItemStack> findCraftableByItems(List<ItemStack> inventoryItems); + + public void registerCategory(IRecipeCategory category); + + public void registerDisplay(Identifier categoryIdentifier, IRecipeDisplay display); + + public Map<IRecipeCategory, List<IRecipeDisplay>> getRecipesFor(ItemStack stack); + + public RecipeManager getRecipeManager(); + + public List<IRecipeCategory> getAllCategories(); + + public Map<IRecipeCategory, List<IRecipeDisplay>> getUsagesFor(ItemStack stack); + + public Optional<SpeedCraftAreaSupplier> getSpeedCraftButtonArea(IRecipeCategory category); + + public void registerSpeedCraftButtonArea(Identifier category, SpeedCraftAreaSupplier rectangle); + + public List<SpeedCraftFunctional> getSpeedCraftFunctional(IRecipeCategory category); + + public void registerSpeedCraftFunctional(Identifier category, SpeedCraftFunctional functional); + + Map<IRecipeCategory, List<IRecipeDisplay>> getAllRecipes(); + +} diff --git a/src/main/java/me/shedaniel/rei/api/IRecipePlugin.java b/src/main/java/me/shedaniel/rei/api/IRecipePlugin.java index 6ba6c70e7..a64ba67a4 100644 --- a/src/main/java/me/shedaniel/rei/api/IRecipePlugin.java +++ b/src/main/java/me/shedaniel/rei/api/IRecipePlugin.java @@ -8,11 +8,11 @@ public interface IRecipePlugin { public void registerItems(IItemRegisterer itemRegisterer); - public void registerPluginCategories(RecipeHelper recipeHelper); + public void registerPluginCategories(IRecipeHelper recipeHelper); - public void registerRecipeDisplays(RecipeHelper recipeHelper); + public void registerRecipeDisplays(IRecipeHelper recipeHelper); - public void registerSpeedCraft(RecipeHelper recipeHelper); + public void registerSpeedCraft(IRecipeHelper recipeHelper); default public int getPriority() { return 0; 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<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getInstance().getRecipesFor(stack); + Map<IRecipeCategory, List<IRecipeDisplay>> 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<IRecipeCategory, List<IRecipeDisplay>> map = RecipeHelper.getInstance().getUsagesFor(stack); + Map<IRecipeCategory, List<IRecipeDisplay>> 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<IRecipeCategory, List<IRecipeDisplay>> 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; diff --git a/src/main/java/me/shedaniel/rei/client/ConfigHelper.java b/src/main/java/me/shedaniel/rei/client/ConfigHelper.java index 2331cb8bd..d31ec4b88 100644 --- a/src/main/java/me/shedaniel/rei/client/ConfigHelper.java +++ b/src/main/java/me/shedaniel/rei/client/ConfigHelper.java @@ -61,72 +61,16 @@ public class ConfigHelper { saveConfig(); } - public REIItemListOrdering getItemListOrdering() { - return config.itemListOrdering; - } - - public void setItemListOrdering(REIItemListOrdering ordering) { - config.itemListOrdering = ordering; - } - - public boolean isAscending() { - return config.isAscending; - } - - public void setAscending(boolean ascending) { - config.isAscending = ascending; + public REIConfig getConfig() { + return config; } public boolean craftableOnly() { - return craftableOnly && config.enableCraftableOnlyButton; + return craftableOnly; } public void toggleCraftableOnly() { craftableOnly = !craftableOnly; } - public boolean showCraftableOnlyButton() { - return config.enableCraftableOnlyButton; - } - - public void setShowCraftableOnlyButton(boolean enableCraftableOnlyButton) { - config.enableCraftableOnlyButton = enableCraftableOnlyButton; - } - - public String getGiveCommandPrefix() { - return config.giveCommandPrefix; - } - - public boolean sideSearchField() { - return config.sideSearchField; - } - - public void setSideSearchField(boolean sideSearchField) { - config.sideSearchField = sideSearchField; - } - - public boolean checkUpdates() { - return config.checkUpdates; - } - - public void setCheckUpdates(boolean checkUpdates) { - config.checkUpdates = checkUpdates; - } - - public boolean isMirrorItemPanel() { - return config.mirrorItemPanel; - } - - public void setMirrorItemPanel(boolean mirrorItemPanel) { - config.mirrorItemPanel = mirrorItemPanel; - } - - public boolean isLoadingDefaultPlugin() { - return config.loadDefaultPlugin; - } - - public void setLoadingDefaultPlugin(boolean loadDefaultPlugin) { - config.loadDefaultPlugin = loadDefaultPlugin; - } - } diff --git a/src/main/java/me/shedaniel/rei/client/REIConfig.java b/src/main/java/me/shedaniel/rei/client/REIConfig.java index be4eabfeb..320cb7afb 100644 --- a/src/main/java/me/shedaniel/rei/client/REIConfig.java +++ b/src/main/java/me/shedaniel/rei/client/REIConfig.java @@ -11,9 +11,15 @@ public class REIConfig { public boolean isAscending = true; public boolean enableCraftableOnlyButton = true; public boolean sideSearchField = false; - public String giveCommandPrefix = "/give"; + public String giveCommand = "/give {player_name} {item_identifier}{nbt} {count}"; + public String gamemodeCommand = "/gamemode {gamemode}"; + public String weatherCommand = "/weather {weather}"; public boolean checkUpdates = true; public boolean mirrorItemPanel = false; public boolean loadDefaultPlugin = true; + public boolean disableCreditsButton = false; + public int maxRecipePerPage = 3; + public boolean fixRamUsage = false; + public boolean showUtilsButtons = false; } diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java index 96490c6dd..10a3b8cfe 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java |
