diff options
| author | Daniel She <shekwancheung0528@gmail.com> | 2019-05-10 00:20:16 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-10 00:20:16 +0800 |
| commit | 67fc756047f34bdbb9f028e48fc725534b3beafc (patch) | |
| tree | 670f0694b3313eaf712020a9d60dc34404725777 /src/main | |
| parent | 766b4837c2512cefa3188adc897605a83144f711 (diff) | |
| parent | 467511401a783fc0a8d625947e69519da1c815e1 (diff) | |
| download | RoughlyEnoughItems-67fc756047f34bdbb9f028e48fc725534b3beafc.tar.gz RoughlyEnoughItems-67fc756047f34bdbb9f028e48fc725534b3beafc.tar.bz2 RoughlyEnoughItems-67fc756047f34bdbb9f028e48fc725534b3beafc.zip | |
Merge pull request #86 from shedaniel/1.14-dev
REi v2.9 (WIP)
Diffstat (limited to 'src/main')
38 files changed, 1147 insertions, 243 deletions
diff --git a/src/main/java/com/zeitheron/hammercore/client/utils/Scissors.java b/src/main/java/com/zeitheron/hammercore/client/utils/Scissors.java new file mode 100644 index 000000000..36d56329d --- /dev/null +++ b/src/main/java/com/zeitheron/hammercore/client/utils/Scissors.java @@ -0,0 +1,38 @@ +package com.zeitheron.hammercore.client.utils; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.util.Window; +import org.lwjgl.opengl.GL11; + +/** + * This is originally the part of Hammer Lib, repacked in REI with permission. + * Adapted GL scissor for minecraft pixel resolution and adjusts (0;0) as left-top corner. + * + * @author Zeitheron + */ +public class Scissors { + public static void begin() { + GL11.glEnable(GL11.GL_SCISSOR_TEST); + } + + public static void scissor(int x, int y, int width, int height) { + Window window = MinecraftClient.getInstance().window; + + int sw = window.getWidth(); + int sh = window.getHeight(); + float dw = window.getScaledWidth(); + float dh = window.getScaledHeight(); + + x = Math.round(sw * (x / dw)); + y = Math.round(sh * (y / dh)); + + width = Math.round(sw * (width / dw)); + height = Math.round(sh * (height / dh)); + + GL11.glScissor(x, sh - height - y, width, height); + } + + public static void end() { + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } +}
\ No newline at end of file diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index 86c234872..d4648bbaa 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -5,8 +5,10 @@ import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; import java.util.List; +import java.util.Map; public interface ClientHelper extends ClientModInitializer { static ClientHelper getInstance() { @@ -19,6 +21,8 @@ public interface ClientHelper extends ClientModInitializer { List<ItemStack> getInventoryItemsTypes(); + void openRecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> map); + void registerFabricKeyBinds(); boolean tryCheatingStack(ItemStack stack); @@ -33,6 +37,10 @@ public interface ClientHelper extends ClientModInitializer { String getFormattedModFromItem(Item item); + String getFormattedModFromIdentifier(Identifier identifier); + + String getModFromIdentifier(Identifier identifier); + FabricKeyBinding getRecipeKeyBinding(); FabricKeyBinding getUsageKeyBinding(); diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 80b7aa167..8304fde90 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -1,6 +1,7 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.gui.RecipeViewingScreen; +import me.shedaniel.rei.gui.renderables.RecipeRenderer; import me.shedaniel.rei.gui.widget.CategoryBaseWidget; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.Widget; @@ -20,8 +21,16 @@ public interface RecipeCategory<T extends RecipeDisplay> { ItemStack getCategoryIcon(); + default Renderer getIcon() { + return Renderable.fromItemStackSupplier(this::getCategoryIcon); + } + String getCategoryName(); + default RecipeRenderer getSimpleRenderer(T recipe) { + return Renderable.fromRecipe(recipe::getInput, recipe::getOutput); + } + default List<Widget> setupDisplay(Supplier<T> recipeDisplaySupplier, Rectangle bounds) { return Collections.singletonList(new RecipeBaseWidget(bounds)); } diff --git a/src/main/java/me/shedaniel/rei/api/Renderable.java b/src/main/java/me/shedaniel/rei/api/Renderable.java new file mode 100644 index 000000000..9059af798 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/Renderable.java @@ -0,0 +1,52 @@ +package me.shedaniel.rei.api; + +import me.shedaniel.rei.gui.renderables.EmptyRenderer; +import me.shedaniel.rei.gui.renderables.ItemStackRenderer; +import me.shedaniel.rei.gui.renderables.SimpleRecipeRenderer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.MathHelper; + +import java.util.List; +import java.util.function.Supplier; + +public interface Renderable { + + static ItemStackRenderer fromItemStackSupplier(Supplier<ItemStack> supplier) { + return new ItemStackRenderer() { + @Override + public ItemStack getItemStack() { + return supplier.get(); + } + }; + } + + static ItemStackRenderer fromItemStack(ItemStack stack) { + return new ItemStackRenderer() { + @Override + public ItemStack getItemStack() { + return stack; + } + }; + } + + static EmptyRenderer empty() { + return EmptyRenderer.INSTANCE; + } + + static SimpleRecipeRenderer fromRecipe(Supplier<List<List<ItemStack>>> input, Supplier<List<ItemStack>> output) { + return new SimpleRecipeRenderer(input, output); + } + + static ItemStackRenderer fromItemStacks(List<ItemStack> stacks) { + return new ItemStackRenderer() { + @Override + public ItemStack getItemStack() { + if (stacks.isEmpty()) + return ItemStack.EMPTY; + return stacks.get(MathHelper.floor((System.currentTimeMillis() / 500 % (double) stacks.size()) / 1f)); + } + }; + } + + void render(int x, int y, double mouseX, double mouseY, float delta); +} diff --git a/src/main/java/me/shedaniel/rei/api/Renderer.java b/src/main/java/me/shedaniel/rei/api/Renderer.java new file mode 100644 index 000000000..569285d84 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/Renderer.java @@ -0,0 +1,13 @@ +package me.shedaniel.rei.api; + +import net.minecraft.client.gui.DrawableHelper; + +public abstract class Renderer extends DrawableHelper implements Renderable { + public int getBlitOffset() { + return this.blitOffset; + } + + public void setBlitOffset(int offset) { + this.blitOffset = offset; + } +} diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java index febe35b4e..832375918 100644 --- a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java @@ -9,7 +9,9 @@ import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.RecipeCategory; import me.shedaniel.rei.api.RecipeDisplay; import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.gui.PreRecipeViewingScreen; import me.shedaniel.rei.gui.RecipeViewingScreen; +import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl; @@ -54,6 +56,14 @@ public class ClientHelperImpl implements ClientHelper { } @Override + public String getFormattedModFromIdentifier(Identifier identifier) { + String mod = getModFromIdentifier(identifier); + if (mod.equalsIgnoreCase("")) + return ""; + return "§9§o" + mod; + } + + @Override public FabricKeyBinding getRecipeKeyBinding() { return recipe; } @@ -78,12 +88,14 @@ public class ClientHelperImpl implements ClientHelper { return nextPage; } + @Override public String getModFromItem(Item item) { if (item.equals(Items.AIR)) return ""; return getModFromIdentifier(Registry.ITEM.getId(item)); } + @Override public String getModFromIdentifier(Identifier identifier) { if (identifier == null) return ""; @@ -147,7 +159,7 @@ public class ClientHelperImpl implements ClientHelper { public boolean executeRecipeKeyBind(ItemStack stack) { Map<RecipeCategory, List<RecipeDisplay>> map = RecipeHelper.getInstance().getRecipesFor(stack); if (map.keySet().size() > 0) - MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); + openRecipeViewingScreen(map); return map.keySet().size() > 0; } @@ -155,7 +167,7 @@ public class ClientHelperImpl implements ClientHelper { public boolean executeUsageKeyBind(ItemStack stack) { Map<RecipeCategory, List<RecipeDisplay>> map = RecipeHelper.getInstance().getUsagesFor(stack); if (map.keySet().size() > 0) - MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); + openRecipeViewingScreen(map); return map.keySet().size() > 0; } @@ -174,11 +186,21 @@ public class ClientHelperImpl implements ClientHelper { public boolean executeViewAllRecipesKeyBind() { Map<RecipeCategory, List<RecipeDisplay>> map = RecipeHelper.getInstance().getAllRecipes(); if (map.keySet().size() > 0) - MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(MinecraftClient.getInstance().window, map)); + openRecipeViewingScreen(map); return map.keySet().size() > 0; } @Override + public void openRecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> map) { + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType == RecipeScreenType.VILLAGER) + MinecraftClient.getInstance().openScreen(new VillagerRecipeViewingScreen(map)); + else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType == RecipeScreenType.UNSET) + MinecraftClient.getInstance().openScreen(new PreRecipeViewingScreen(map)); + else + MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(map)); + } + + @Override public void onInitializeClient() { ClientHelperImpl.instance = (ClientHelperImpl) this; registerFabricKeyBinds(); diff --git a/src/main/java/me/shedaniel/rei/client/ConfigObject.java b/src/main/java/me/shedaniel/rei/client/ConfigObject.java index af100f3fc..3522b6f3b 100644 --- a/src/main/java/me/shedaniel/rei/client/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/client/ConfigObject.java @@ -48,6 +48,8 @@ public class ConfigObject { public boolean lightGrayRecipeBorder = false; + public RecipeScreenType screenType = RecipeScreenType.UNSET; + @Comment( "The location of choose page dialog, will automatically be set to your last location so there is no need to change this.") public RelativePoint choosePageDialogPoint = new RelativePoint(.5, .5); diff --git a/src/main/java/me/shedaniel/rei/client/RecipeScreenType.java b/src/main/java/me/shedaniel/rei/client/RecipeScreenType.java new file mode 100644 index 000000000..4975e3576 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/client/RecipeScreenType.java @@ -0,0 +1,16 @@ +package me.shedaniel.rei.client; + +import net.minecraft.client.resource.language.I18n; + +import java.util.Locale; + +public enum RecipeScreenType { + UNSET, + ORIGINAL, + VILLAGER; + + @Override + public String toString() { + return I18n.translate("text.rei.config.recipe_screen_type." + name().toLowerCase()); + } +} diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index f1b6fb700..71a274151 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -27,13 +27,15 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.world.GameMode; import java.awt.*; -import java.util.*; +import java.util.LinkedList; import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; public class ContainerScreenOverlay extends AbstractParentElement implements Drawable { - private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui" + "/recipecontainer.png"); + private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); private static final List<QueuedTooltip> QUEUED_TOOLTIPS = Lists.newArrayList(); public static String searchTerm = ""; private static int page = 0; @@ -43,7 +45,6 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra private Window window; private CraftableToggleButtonWidget toggleButtonWidget; private ButtonWidget buttonLeft, buttonRight; - private int lastLeft; public static ItemListOverlay getItemListOverlay() { return itemListOverlay; @@ -59,7 +60,6 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra this.window = MinecraftClient.getInstance().window; DisplayHelper.DisplayBoundsHandler boundsHandler = RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); this.rectangle = RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? boundsHandler.getLeftBounds(MinecraftClient.getInstance().currentScreen) : boundsHandler.getRightBounds(MinecraftClient.getInstance().currentScreen); - this.lastLeft = getLeft(); widgets.add(itemListOverlay = new ItemListOverlay(page)); itemListOverlay.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, false); @@ -306,6 +306,10 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra RecipeViewingScreen widget = (RecipeViewingScreen) MinecraftClient.getInstance().currentScreen; return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width - widthRemoved, 18); } + if (MinecraftClient.getInstance().currentScreen instanceof VillagerRecipeViewingScreen) { + VillagerRecipeViewingScreen widget = (VillagerRecipeViewingScreen) MinecraftClient.getInstance().currentScreen; + return new Rectangle(widget.bounds.x, window.getScaledHeight() - 22, widget.bounds.width - widthRemoved, 18); + } return new Rectangle(ScreenHelper.getLastContainerScreenHooks().rei_getContainerLeft(), window.getScaledHeight() - 22, ScreenHelper.getLastContainerScreenHooks().rei_getContainerWidth() - widthRemoved, 18); } @@ -427,16 +431,6 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra GuiLighting.disable(); } - private int getLeft() { - if (MinecraftClient.getInstance().currentScreen instanceof RecipeViewingScreen) { - RecipeViewingScreen widget = (RecipeViewingScreen) MinecraftClient.getInstance().currentScreen; - return widget.getBounds().x; - } - if (MinecraftClient.getInstance().player.getRecipeBook().isGuiOpen()) - return ScreenHelper.getLastContainerScreenHooks().rei_getContainerLeft() - 147 - 30; - return ScreenHelper.getLastContainerScreenHooks().rei_getContainerLeft(); - } - private int getTotalPage() { return itemListOverlay.getTotalPage(); } diff --git a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java new file mode 100644 index 000000000..68ddc78a0 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -0,0 +1,133 @@ +package me.shedaniel.rei.gui; + +import com.google.common.collect.Lists; +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.ClientHelper; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.client.RecipeScreenType; +import me.shedaniel.rei.client.ScreenHelper; +import me.shedaniel.rei.gui.widget.ButtonWidget; +import me.shedaniel.rei.gui.widget.HighlightableWidget; +import me.shedaniel.rei.gui.widget.Widget; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.audio.PositionedSoundInstance; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Screen; +import net.minecraft.client.render.GuiLighting; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.sound.SoundEvents; +import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.util.Identifier; + +import java.awt.*; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class PreRecipeViewingScreen extends Screen { + + private static final Identifier IDENTIFIER = new Identifier("roughlyenoughitems", "textures/gui/screenshot.png"); + private final List<Widget> widgets; + private boolean original; + private Map<RecipeCategory, List<RecipeDisplay>> map; + + public PreRecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> map) { + super(new TranslatableTextComponent("text.rei.recipe_screen_type.selection")); + this.widgets = Lists.newArrayList(); + this.original = true; + this.map = map; + } + + @Override + protected void init() { + this.children.clear(); + this.widgets.clear(); + this.widgets.add(new ButtonWidget(width / 2 - 100, height - 40, 200, 20, I18n.translate("text.rei.select")) { + @Override + public void onPressed() { + RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType = original ? RecipeScreenType.ORIGINAL : RecipeScreenType.VILLAGER; + try { + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); + } catch (IOException e) { + e.printStackTrace(); + } + ClientHelper.getInstance().openRecipeViewingScreen(map); + } + }); + this.widgets.add(new ScreenTypeSelection(width / 2 - 200 - 5, height / 2 - 112 / 2 - 10, 0)); + this.widgets.add(new ScreenTypeSelection(width / 2 + 5, height / 2 - 112 / 2 - 10, 112)); + this.children.addAll(widgets); + } + + @Override + public void render(int int_1, int int_2, float float_1) { + this.renderBackground(); + this.drawCenteredString(this.font, this.title.getFormattedText(), this.width / 2, 20, 16777215); + int i = 30; + for(String s : this.font.wrapStringToWidthAsList(I18n.translate("text.rei.recipe_screen_type.selection.sub"), width - 30)) { + this.drawCenteredString(this.font, "§7" + s, width / 2, i, -1); + i += 10; + } + super.render(int_1, int_2, float_1); + this.widgets.forEach(widget -> { + GuiLighting.disable(); + widget.render(int_1, int_2, float_1); + }); + } + + @Override + public boolean keyPressed(int int_1, int int_2, int int_3) { + if ((int_1 == 256 || this.minecraft.options.keyInventory.matchesKey(int_1, int_2)) && this.shouldCloseOnEsc()) { + MinecraftClient.getInstance().openScreen(ScreenHelper.getLastContainerScreen()); + ScreenHelper.getLastOverlay().init(); + return true; + } + return super.keyPressed(int_1, int_2, int_3); + } + + public class ScreenTypeSelection extends HighlightableWidget { + + private Rectangle bounds; + private int u, v; + + public ScreenTypeSelection(int x, int y, int v) { + this.bounds = new Rectangle(x - 4, y - 4, 208, 120); + this.u = 0; + this.v = v; + } + + @Override + public Rectangle getBounds() { + return bounds; + } + + @Override + public void render(int i, int i1, float delta) { + MinecraftClient.getInstance().getTextureManager().bindTexture(IDENTIFIER); + blit(bounds.x + 4, bounds.y + 4, u, v, 200, 112); + if (original == (v == 0)) { + fillGradient(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + 2, 0xFFFFFFFF, 0xFFFFFFFF); + fillGradient(bounds.x, bounds.y + bounds.height - 2, bounds.x + bounds.width, bounds.y + bounds.height, 0xFFFFFFFF, 0xFFFFFFFF); + fillGradient(bounds.x, bounds.y, bounds.x + 2, bounds.y + bounds.height, 0xFFFFFFFF, 0xFFFFFFFF); + fillGradient(bounds.x + bounds.width - 2, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, 0xFFFFFFFF, 0xFFFFFFFF); + } + } + + @Override + public boolean mouseClicked(double double_1, double double_2, int int_1) { + if (isHighlighted(double_1, double_2)) { + minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + original = (v == 0); + return true; + } + return false; + } + + @Override + public List<? extends Element> children() { + return Collections.emptyList(); + } + } +} diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 16af460f4..2bb1b4486 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -43,16 +43,15 @@ public class RecipeViewingScreen extends Screen { public int largestWidth, largestHeight; public boolean choosePageActivated; public RecipeChoosePageWidget recipeChoosePageWidget; - private Window window; private Rectangle bounds; private RecipeCategory selectedCategory; private ButtonWidget recipeBack, recipeNext, categoryBack, categoryNext; - public RecipeViewingScreen(Window window, Map<RecipeCategory, List<RecipeDisplay>> categoriesMap) { + public RecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> categoriesMap) { super(new StringTextComponent("")); this.categoryPages = 0; - this.window = window; this.widgets = Lists.newArrayList(); + Window window = MinecraftClient.getInstance().window; this.bounds = new Rectangle(window.getScaledWidth() / 2 - guiWidth / 2, window.getScaledHeight() / 2 - guiHeight / 2, 176, 186); this.categoriesMap = categoriesMap; this.categories = Lists.newArrayList(); @@ -119,11 +118,11 @@ public class RecipeViewingScreen extends Screen { this.children.clear(); this.tabs.clear(); this.widgets.clear(); - this.largestWidth = window.getScaledWidth() - 100; - this.largestHeight = window.getScaledHeight() - 40; + this.largestWidth = width - 100; + this.largestHeight = height - 40; this.guiWidth = MathHelper.clamp(getCurrentDisplayed().stream().map(display -> selectedCategory.getDisplayWidth(display)).max( |
