aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/plugin
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-01-11 00:34:07 +0800
committershedaniel <daniel@shedaniel.me>2020-01-11 00:34:07 +0800
commita855c0284c3b285dd8a71b57ec35702995ae5b30 (patch)
tree4b2876163d99301960a26ff821aff5c97e3fb02e /src/main/java/me/shedaniel/rei/plugin
parentbde33221f4e4732daafdc9ecd3a0e559c1f74ed2 (diff)
downloadRoughlyEnoughItems-a855c0284c3b285dd8a71b57ec35702995ae5b30.tar.gz
RoughlyEnoughItems-a855c0284c3b285dd8a71b57ec35702995ae5b30.tar.bz2
RoughlyEnoughItems-a855c0284c3b285dd8a71b57ec35702995ae5b30.zip
3.3.7
Diffstat (limited to 'src/main/java/me/shedaniel/rei/plugin')
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java29
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java1
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java275
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationDisplay.java75
4 files changed, 376 insertions, 4 deletions
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
index 5513b2fe8..0f04e72d0 100644
--- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
+++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java
@@ -30,6 +30,8 @@ import me.shedaniel.rei.plugin.crafting.DefaultShapedDisplay;
import me.shedaniel.rei.plugin.crafting.DefaultShapelessDisplay;
import me.shedaniel.rei.plugin.fuel.DefaultFuelCategory;
import me.shedaniel.rei.plugin.fuel.DefaultFuelDisplay;
+import me.shedaniel.rei.plugin.information.DefaultInformationCategory;
+import me.shedaniel.rei.plugin.information.DefaultInformationDisplay;
import me.shedaniel.rei.plugin.smelting.DefaultSmeltingDisplay;
import me.shedaniel.rei.plugin.smoking.DefaultSmokingDisplay;
import me.shedaniel.rei.plugin.stonecutting.DefaultStoneCuttingCategory;
@@ -69,9 +71,11 @@ public class DefaultPlugin implements REIPluginV0 {
public static final Identifier PLUGIN = new Identifier("roughlyenoughitems", "default_plugin");
public static final Identifier COMPOSTING = new Identifier("minecraft", "plugins/composting");
public static final Identifier FUEL = new Identifier("minecraft", "plugins/fuel");
+ public static final Identifier INFO = new Identifier("roughlyenoughitems", "plugins/information");
private static final Identifier DISPLAY_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/display.png");
private static final Identifier DISPLAY_TEXTURE_DARK = new Identifier("roughlyenoughitems", "textures/gui/display_dark.png");
private static final List<DefaultBrewingDisplay> BREWING_DISPLAYS = Lists.newArrayList();
+ private static final List<DefaultInformationDisplay> INFO_DISPLAYS = Lists.newArrayList();
public static Identifier getDisplayTexture() {
return ScreenHelper.isDarkModeEnabled() ? DISPLAY_TEXTURE_DARK : DISPLAY_TEXTURE;
@@ -81,6 +85,10 @@ public class DefaultPlugin implements REIPluginV0 {
BREWING_DISPLAYS.add(display);
}
+ public static void registerInfoDisplay(DefaultInformationDisplay display) {
+ INFO_DISPLAYS.add(display);
+ }
+
@Override
public Identifier getPluginIdentifier() {
return PLUGIN;
@@ -92,6 +100,11 @@ public class DefaultPlugin implements REIPluginV0 {
}
@Override
+ public void preRegister() {
+ INFO_DISPLAYS.clear();
+ }
+
+ @Override
public void registerEntries(EntryRegistry entryRegistry) {
if (!ConfigObject.getInstance().isLoadingDefaultPlugin()) {
return;
@@ -149,6 +162,13 @@ public class DefaultPlugin implements REIPluginV0 {
if (!ConfigObject.getInstance().isLoadingDefaultPlugin()) {
return;
}
+ // DefaultPlugin.registerInfoDisplay(DefaultInformationDisplay.createFromEntry(EntryStack.create(Items.FURNACE), new LiteralText("Furnace Info"))
+ // .lines(new LiteralText("Furnace is a nice block, crafted using 8 cobblestone."),
+ // new LiteralText("An amazing tool to burn lil taters."),
+ // new LiteralText("Now available in a store next to you."),
+ // new LiteralText("Now with 60% off for an limited time!"),
+ // new LiteralText("Get it with coupon code: ").append(new LiteralText("TATERS").formatted(Formatting.BOLD))
+ // ));
recipeHelper.registerRecipes(CRAFTING, ShapelessRecipe.class, DefaultShapelessDisplay::new);
recipeHelper.registerRecipes(CRAFTING, ShapedRecipe.class, DefaultShapedDisplay::new);
recipeHelper.registerRecipes(SMELTING, SmeltingRecipe.class, DefaultSmeltingDisplay::new);
@@ -186,9 +206,7 @@ public class DefaultPlugin implements REIPluginV0 {
map.put(entry.getKey(), entry.getFloatValue());
}
List<ItemConvertible> stacks = new LinkedList<>(map.keySet());
- stacks.sort((first, second) -> {
- return (int) ((map.get(first) - map.get(second)) * 100);
- });
+ stacks.sort((first, second) -> (int) ((map.get(first) - map.get(second)) * 100));
for (int i = 0; i < stacks.size(); i += MathHelper.clamp(48, 1, stacks.size() - i)) {
List<ItemConvertible> thisStacks = Lists.newArrayList();
for (int j = i; j < i + 48; j++)
@@ -203,6 +221,10 @@ public class DefaultPlugin implements REIPluginV0 {
@Override
public void postRegister() {
+ RecipeHelper.getInstance().registerCategory(new DefaultInformationCategory());
+ for (DefaultInformationDisplay display : INFO_DISPLAYS) {
+ RecipeHelper.getInstance().registerDisplay(INFO, display);
+ }
// Sit tight! This will be a fast journey!
long time = System.currentTimeMillis();
for (EntryStack stack : EntryRegistry.getInstance().getStacksList())
@@ -321,6 +343,7 @@ public class DefaultPlugin implements REIPluginV0 {
recipeHelper.registerWorkingStations(COMPOSTING, EntryStack.create(Items.COMPOSTER));
recipeHelper.removeAutoCraftButton(FUEL);
recipeHelper.removeAutoCraftButton(COMPOSTING);
+ recipeHelper.removeAutoCraftButton(INFO);
recipeHelper.registerScreenClickArea(new Rectangle(88, 32, 28, 23), CraftingTableScreen.class, CRAFTING);
recipeHelper.registerScreenClickArea(new Rectangle(137, 29, 10, 13), InventoryScreen.class, CRAFTING);
recipeHelper.registerScreenClickArea(new Rectangle(97, 16, 14, 30), BrewingStandScreen.class, BREWING);
diff --git a/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java b/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java
index 96d3e2027..d427dc1a2 100644
--- a/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java
+++ b/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java
@@ -104,7 +104,6 @@ public class DefaultCompostingCategory implements RecipeCategory<DefaultComposti
return 140;
}
- @SuppressWarnings("deprecation")
@Override
public int getFixedRecipesPerPage() {
return 1;
diff --git a/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java b/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java
new file mode 100644
index 000000000..bb5095628
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java
@@ -0,0 +1,275 @@
+package me.shedaniel.rei.plugin.information;
+
+import com.google.common.collect.Lists;
+import com.mojang.blaze3d.systems.RenderSystem;
+import me.shedaniel.clothconfig2.ClothConfigInitializer;
+import me.shedaniel.clothconfig2.api.ScissorsHandler;
+import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget;
+import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget;
+import me.shedaniel.math.api.Point;
+import me.shedaniel.math.api.Rectangle;
+import me.shedaniel.math.impl.PointHelper;
+import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.api.RecipeCategory;
+import me.shedaniel.rei.gui.entries.RecipeEntry;
+import me.shedaniel.rei.gui.widget.*;
+import me.shedaniel.rei.impl.RenderingEntry;
+import me.shedaniel.rei.impl.ScreenHelper;
+import me.shedaniel.rei.plugin.DefaultPlugin;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.Element;
+import net.minecraft.client.render.BufferBuilder;
+import net.minecraft.client.render.BufferRenderer;
+import net.minecraft.client.render.Tessellator;
+import net.minecraft.client.render.VertexFormats;
+import net.minecraft.client.resource.language.I18n;
+import net.minecraft.client.util.Texts;
+import net.minecraft.client.util.math.Matrix4f;
+import net.minecraft.text.Text;
+import net.minecraft.util.Identifier;
+import net.minecraft.util.math.MathHelper;
+
+import javax.annotation.Nullable;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Supplier;
+
+public class DefaultInformationCategory implements RecipeCategory<DefaultInformationDisplay> {
+ @Override
+ public Identifier getIdentifier() {
+ return DefaultPlugin.INFO;
+ }
+
+ @Override
+ public String getCategoryName() {
+ return I18n.translate("category.rei.information");
+ }
+
+ @Override
+ public RecipeEntry getSimpleRenderer(DefaultInformationDisplay recipe) {
+ Text name = recipe.getName();
+ return new RecipeEntry() {
+ @Override
+ public int getHeight() {
+ return 10 + MinecraftClient.getInstance().textRenderer.fontHeight;
+ }
+
+ @Nullable
+ @Override
+ public QueuedTooltip getTooltip(int mouseX, int mouseY) {
+ return null;
+ }
+
+ @Override
+ public void render(Rectangle rectangle, int mouseX, int mouseY, float delta) {
+ MinecraftClient.getInstance().textRenderer.draw(name.asFormattedString(), rectangle.x + 5, rectangle.y + 6, -1);
+ }
+ };
+ }
+
+ @Override
+ public EntryStack getLogo() {
+ return new RenderingEntry() {
+ @Override
+ public void render(Rectangle bounds, int mouseX, int mouseY, float delta) {
+ MinecraftClient.getInstance().getTextureManager().bindTexture(DefaultPlugin.getDisplayTexture());
+ Matrix4f matrix4f = Matrix4f.method_24021(-1.2f, -1, 0);
+ DefaultInformationCategory.innerBlit(matrix4f, bounds.getCenterX() - 8, bounds.getCenterX() + 8, bounds.getCenterY() - 8, bounds.getCenterY() + 8, 0, 116f / 256f, (116f + 16f) / 256f, 0f, 16f / 256f);
+ }
+ };
+ }
+
+ protected static void innerBlit(Matrix4f matrix4f, int xStart, int xEnd, int yStart, int yEnd, int z, float uStart, float uEnd, float vStart, float vEnd) {
+ BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
+ bufferBuilder.begin(7, VertexFormats.POSITION_TEXTURE);
+ bufferBuilder.vertex(matrix4f, xStart, yEnd, z).texture(uStart, vEnd).next();
+ bufferBuilder.vertex(matrix4f, xEnd, yEnd, z).texture(uEnd, vEnd).next();
+ bufferBuilder.vertex(matrix4f, xEnd, yStart, z).texture(uEnd, vStart).next();
+ bufferBuilder.vertex(matrix4f, xStart, yStart, z).texture(uStart, vStart).next();
+ bufferBuilder.end();
+ RenderSystem.enableAlphaTest();
+ BufferRenderer.draw(bufferBuilder);
+ }
+
+ @Override
+ public List<Widget> setupDisplay(Supplier<DefaultInformationDisplay> recipeDisplaySupplier, Rectangle bounds) {
+ DefaultInformationDisplay display = recipeDisplaySupplier.get();
+ List<Widget> widgets = Lists.newArrayList();
+ widgets.add(new LabelWidget(new Point(bounds.getCenterX(), bounds.y + 3), display.getName().asFormattedString()).noShadow().color(ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 0xFF404040));
+ widgets.add(EntryWidget.create(bounds.getCenterX() - 8, bounds.y + 15).entries(display.getEntryStacks()));
+ Rectangle rectangle = new Rectangle(bounds.getCenterX() - (bounds.width / 2), bounds.y + 35, bounds.width, bounds.height - 40);
+ widgets.add(new SlotBaseWidget(rectangle));
+ widgets.add(new ScrollableTextWidget(rectangle, display.getTexts()));
+ return widgets;
+ }
+
+ @Override
+ public int getDisplayHeight() {
+ return 140;
+ }
+
+ @Override
+ public int getFixedRecipesPerPage() {
+ return 1;
+ }
+
+ private static class ScrollableTextWidget extends WidgetWithBounds {
+ private Rectangle bounds;
+ private List<Text> texts;
+ private double target;
+ private double scroll;
+ private long start;
+ private long duration;
+
+ public ScrollableTextWidget(Rectangle bounds, List<Text> texts) {
+ this.bounds = bounds;
+ this.texts = Lists.newArrayList();
+ for (Text text : texts) {
+ if (!this.texts.isEmpty())
+ this.texts.add(null);
+ this.texts.addAll(Texts.wrapLines(text, bounds.width - 11, MinecraftClient.getInstance().textRenderer, true, false));
+ }
+ }
+
+ @Override
+ public boolean mouseScrolled(double double_1, double double_2, double double_3) {
+ if (containsMouse(double_1, double_2)) {
+ offset(ClothConfigInitializer.getScrollStep() * -double_3, true);
+ return true;
+ }
+ return false;
+ }
+
+ public void offset(double value, boolean animated) {
+ scrollTo(target + value, animated);
+ }
+
+ public void scrollTo(double value, boolean animated) {
+ scrollTo(value, animated, ClothConfigInitializer.getScrollDuration());
+ }
+
+ public void scrollTo(double value, boolean animated, long duration) {
+ target = clamp(value);
+
+ if (animated) {
+ start = System.currentTimeMillis();
+ this.duration = duration;
+ } else
+ scroll = target;
+ }
+
+ public final double clamp(double v) {
+ return clamp(v, DynamicEntryListWidget.SmoothScrollingSettings.CLAMP_EXTENSION);
+ }
+
+ public final double clamp(double v, double clampExtension) {
+ return MathHelper.clamp(v, -clampExtension, getMaxScroll() + clampExtension);
+ }
+
+ protected int getMaxScroll() {
+ return Math.max(0, this.getMaxScrollPosition() - this.getBounds().height + 4);
+ }
+
+ protected int getMaxScrollPosition() {
+ int i = 0;
+ for (Text entry : texts) {
+ i += entry == null ? 4 : font.fontHeight;
+ }
+ return i;
+ }
+
+ @Override
+ public Rectangle getBounds() {
+ return bounds;
+ }
+
+ @Override
+ public void render(int mouseX, int mouseY, float delta) {
+ updatePosition(delta);
+ Rectangle innerBounds = new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 7, bounds.height - 2);
+ ScissorsHandler.INSTANCE.scissor(innerBounds);
+ int currentY = (int) -scroll + innerBounds.y;
+ for (Text text : texts) {
+ if (text != null && currentY + font.fontHeight >= innerBounds.y && currentY <= innerBounds.getMaxY()) {
+ font.draw(text.asFormattedString(), innerBounds.x + 2, currentY + 2, ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 0xFF090909);
+ }
+ currentY += text == null ? 4 : font.fontHeight;
+ }
+ ScissorsHandler.INSTANCE.removeLastScissor();
+ ScissorsHandler.INSTANCE.scissor(bounds);
+ RenderSystem.enableBlend();
+ RenderSystem.blendFuncSeparate(770, 771, 0, 1);
+ RenderSystem.disableAlphaTest();
+ RenderSystem.shadeModel(7425);
+ RenderSystem.disableTexture();
+ renderScrollBar();
+ RenderSystem.enableTexture();
+ RenderSystem.shadeModel(7424);
+ RenderSystem.enableAlphaTest();
+ RenderSystem.disableBlend();
+ ScissorsHandler.INSTANCE.removeLastScissor();
+ }
+
+ @SuppressWarnings("deprecation")
+ private void renderScrollBar() {
+ int maxScroll = getMaxScroll();
+ int scrollbarPositionMinX = getBounds().getMaxX() - 7;
+ int scrollbarPositionMaxX = scrollbarPositionMinX + 6;
+ Tessellator tessellator = Tessellator.getInstance();
+ BufferBuilder buffer = tessellator.getBuffer();
+ if (maxScroll > 0) {
+ int height = (int) (((this.getBounds().height - 2f) * (this.getBounds().height - 2f)) / this.getMaxScrollPosition());
+ height = MathHelper.clamp(height, 32, this.getBounds().height - 2);
+ height -= Math.min((scroll < 0 ? (int) -scroll : scroll > maxScroll ? (int) scroll - maxScroll : 0), height * .95);
+ height = Math.max(10, height);
+ int minY = Math.min(Math.max((int) scroll * (this.getBounds().height - 2 - height) / maxScroll + getBounds().y + 1, getBounds().y + 1), getBounds().getMaxY() -1 - height);
+
+ boolean hovered = new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height).contains(PointHelper.fromMouse());
+ int bottomC = hovered ? 168 : 128;
+ int topC = hovered ? 222 : 172;
+
+ // Black Bar
+ buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
+ buffer.vertex(scrollbarPositionMinX, this.getBounds().y + 1, 0.0D).texture(0, 1).color(0, 0, 0, 255).next();
+ buffer.vertex(scrollbarPositionMaxX, this.getBounds().y + 1, 0.0D).texture(1, 1).color(0, 0, 0, 255).next();
+ buffer.vertex(scrollbarPositionMaxX, getBounds().getMaxY() - 1, 0.0D).texture(1, 0).color(0, 0, 0, 255).next();
+ buffer.vertex(scrollbarPositionMinX, getBounds().getMaxY() - 1, 0.0D).texture(0, 0).color(0, 0, 0, 255).next();
+ tessellator.draw();
+
+ // Bottom
+ buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
+ buffer.vertex(scrollbarPositionMinX, minY + height, 0.0D).texture(0, 1).color(bottomC, bottomC, bottomC, 255).next();
+ buffer.vertex(scrollbarPositionMaxX, minY + height, 0.0D).texture(1, 1).color(bottomC, bottomC, bottomC, 255).next();
+ buffer.vertex(scrollbarPositionMaxX, minY, 0.0D).texture(1, 0).color(bottomC, bottomC, bottomC, 255).next();
+ buffer.vertex(scrollbarPositionMinX, minY, 0.0D).texture(0, 0).color(bottomC, bottomC, bottomC, 255).next();
+ tessellator.draw();
+
+ // Top
+ buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
+ buffer.vertex(scrollbarPositionMinX, (minY + height - 1), 0.0D).texture(0, 1).color(topC, topC, topC, 255).next();
+ buffer.vertex((scrollbarPositionMaxX - 1), (minY + height - 1), 0.0D).texture(1, 1).color(topC, topC, topC, 255).next();
+ buffer.vertex((scrollbarPositionMaxX - 1), minY, 0.0D).texture(1, 0).color(topC, topC, topC, 255).next();
+ buffer.vertex(scrollbarPositionMinX, minY, 0.0D).texture(0, 0).color(topC, topC, topC, 255).next();
+ tessellator.draw();
+ }
+ }
+
+ private void updatePosition(float delta) {
+ target = clamp(target);
+ if (target < 0) {
+ target -= target * (1 - ClothConfigInitializer.getBounceBackMultiplier()) * delta / 3;
+ } else if (target > getMaxScroll()) {
+ target = (target - getMaxScroll()) * (1 - (1 - ClothConfigInitializer.getBounceBackMultiplier()) * delta / 3) + getMaxScroll();
+ }
+ if (!DynamicNewSmoothScrollingEntryListWidget.Precision.almostEquals(scroll, target, DynamicNewSmoothScrollingEntryListWidget.Precision.FLOAT_EPSILON))
+ scroll = (float) DynamicNewSmoothScrollingEntryListWidget.Interpolation.expoEase(scroll, target, Math.min((System.currentTimeMillis() - start) / ((double) duration), 1));
+ else
+ scroll = target;
+ }
+
+ @Override
+ public List<? extends Element> children() {
+ return Collections.emptyList();
+ }
+ }
+}
diff --git a/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationDisplay.java b/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationDisplay.java
new file mode 100644
index 000000000..84f8c2bbd
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationDisplay.java
@@ -0,0 +1,75 @@
+package me.shedaniel.rei.plugin.information;
+
+import com.google.common.collect.Lists;
+import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.api.RecipeDisplay;
+import me.shedaniel.rei.plugin.DefaultPlugin;
+import net.minecraft.text.Text;
+import net.minecraft.util.Identifier;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+public class DefaultInformationDisplay implements RecipeDisplay {
+ private List<EntryStack> entryStacks;
+ private List<Text> texts;
+ private Text name;
+
+ protected DefaultInformationDisplay(List<EntryStack> entryStacks, Text name) {
+ this.entryStacks = entryStacks;
+ this.name = name;
+ this.texts = Lists.newArrayList();
+ }
+
+ public static DefaultInformationDisplay createFromEntries(List<EntryStack> entryStacks, Text name) {
+ return new DefaultInformationDisplay(entryStacks, name);
+ }
+
+ public static DefaultInformationDisplay createFromEntry(EntryStack entryStack, Text name) {
+ return createFromEntries(Collections.singletonList(entryStack), name);
+ }
+
+ @Override
+ public List<List<EntryStack>> getInputEntries() {
+ return Collections.singletonList(entryStacks);
+ }
+
+ @Override
+ public List<EntryStack> getOutputEntries() {
+ return Collections.emptyList();
+ }
+
+ public DefaultInformationDisplay line(Text line) {
+ texts.add(line);
+ return this;
+ }
+
+ public DefaultInformationDisplay lines(Text... lines) {
+ texts.addAll(Arrays.asList(lines));
+ return this;
+ }
+
+ public DefaultInformationDisplay lines(Collection<Text> lines) {
+ texts.addAll(lines);
+ return this;
+ }
+
+ List<EntryStack> getEntryStacks() {
+ return entryStacks;
+ }
+
+ Text getName() {
+ return name;
+ }
+
+ List<Text> getTexts() {
+ return texts;
+ }
+
+ @Override
+ public Identifier getRecipeCategory() {
+ return DefaultPlugin.INFO;
+ }
+}