|
@@ -6,19 +6,21 @@
|
|
|
package me.shedaniel.rei.gui.widget;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import com.zeitheron.hammercore.client.utils.Scissors;
|
|
|
-import me.shedaniel.clothconfig2.api.RunSixtyTimesEverySec;
|
|
|
+import me.shedaniel.clothconfig2.ClothConfigInitializer;
|
|
|
+import me.shedaniel.clothconfig2.api.ScissorsHandler;
|
|
|
+import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget.Interpolation;
|
|
|
+import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget.Precision;
|
|
|
import me.shedaniel.math.api.Rectangle;
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
|
|
import me.shedaniel.math.impl.PointHelper;
|
|
|
import me.shedaniel.rei.RoughlyEnoughItemsCore;
|
|
|
import me.shedaniel.rei.api.*;
|
|
|
+import me.shedaniel.rei.api.annotations.ToBeRemoved;
|
|
|
import me.shedaniel.rei.gui.config.ItemCheatingMode;
|
|
|
import me.shedaniel.rei.gui.config.ItemListOrdering;
|
|
|
-import me.shedaniel.rei.gui.renderers.FluidRenderer;
|
|
|
-import me.shedaniel.rei.gui.renderers.ItemStackRenderer;
|
|
|
import me.shedaniel.rei.impl.ScreenHelper;
|
|
|
import me.shedaniel.rei.impl.SearchArgument;
|
|
|
+import me.shedaniel.rei.utils.CollectionUtils;
|
|
|
import net.minecraft.client.MinecraftClient;
|
|
|
import net.minecraft.client.item.TooltipContext;
|
|
|
import net.minecraft.client.network.ClientPlayerEntity;
|
|
@@ -33,55 +35,27 @@ import net.minecraft.item.ItemGroup;
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
import net.minecraft.text.Text;
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
-import net.minecraft.util.Formatting;
|
|
|
import net.minecraft.util.Identifier;
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
import net.minecraft.util.registry.Registry;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
-import javax.annotation.Nullable;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
+import java.util.function.Supplier;
|
|
|
|
|
|
+@SuppressWarnings({"deprecation", "rawtypes"})
|
|
|
public class EntryListWidget extends Widget {
|
|
|
|
|
|
+ private static final Supplier<Boolean> RENDER_EXTRA_CONFIG = () -> RoughlyEnoughItemsCore.getConfigManager().getConfig().doesRenderEntryExtraOverlay();
|
|
|
private static final String SPACE = " ", EMPTY = "";
|
|
|
- private static final Comparator<Entry> ASCENDING_COMPARATOR;
|
|
|
+ private static final Comparator<EntryStack> ASCENDING_COMPARATOR;
|
|
|
private static List<Item> searchBlacklisted = Lists.newArrayList();
|
|
|
private static float scroll;
|
|
|
- private static float scrollVelocity;
|
|
|
+ private static float target;
|
|
|
+ private static long start;
|
|
|
+ private static long duration;
|
|
|
private static float maxScroll;
|
|
|
- protected static RunSixtyTimesEverySec scroller = () -> {
|
|
|
- try {
|
|
|
- if (scrollVelocity == 0.0F && scroll >= 0.0F && scroll <= getMaxScroll()) {
|
|
|
- scrollerUnregisterTick();
|
|
|
- } else {
|
|
|
- float change = scrollVelocity * 0.3F;
|
|
|
- if (scrollVelocity != 0) {
|
|
|
- scroll += change;
|
|
|
- scrollVelocity -= scrollVelocity * (scroll >= 0.0F && scroll <= getMaxScroll() ? 0.2D : 0.4D);
|
|
|
- if (Math.abs(scrollVelocity) < 0.1F) {
|
|
|
- scrollVelocity = 0.0F;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (scroll < 0.0F && scrollVelocity == 0.0F) {
|
|
|
- scroll = Math.min(scroll + (0.0F - scroll) * 0.2F, 0.0F);
|
|
|
- if (Math.abs(scroll) < 0.1F)
|
|
|
- scroll = 0.0F;
|
|
|
- } else if (scroll > getMaxScroll() && scrollVelocity == 0.0F) {
|
|
|
- scroll = Math.max(scroll - (scroll - getMaxScroll()) * 0.2F, getMaxScroll());
|
|
|
- if (scroll > getMaxScroll() && scroll < getMaxScroll() + 0.1F) {
|
|
|
- scroll = getMaxScroll();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- };
|
|
|
private static float scrollBarAlpha = 0;
|
|
|
private static float scrollBarAlphaFuture = 0;
|
|
|
private static long scrollBarAlphaFutureTime = -1;
|
|
@@ -90,9 +64,9 @@ public class EntryListWidget extends Widget {
|
|
|
static {
|
|
|
ASCENDING_COMPARATOR = (entry, entry1) -> {
|
|
|
if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemListOrdering().equals(ItemListOrdering.name))
|
|
|
- return tryGetEntryName(entry).compareToIgnoreCase(tryGetEntryName(entry1));
|
|
|
+ return tryGetEntryStackName(entry).compareToIgnoreCase(tryGetEntryStackName(entry1));
|
|
|
if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemListOrdering().equals(ItemListOrdering.item_groups)) {
|
|
|
- if (entry.getEntryType() == Entry.Type.ITEM && entry1.getEntryType() == Entry.Type.ITEM) {
|
|
|
+ if (entry.getType() == EntryStack.Type.ITEM && entry1.getType() == EntryStack.Type.ITEM) {
|
|
|
ItemStack stack0 = entry.getItemStack();
|
|
|
ItemStack stack1 = entry1.getItemStack();
|
|
|
List<ItemGroup> itemGroups = Arrays.asList(ItemGroup.GROUPS);
|
|
@@ -104,7 +78,7 @@ public class EntryListWidget extends Widget {
|
|
|
}
|
|
|
|
|
|
private final List<SearchArgument[]> lastSearchArgument;
|
|
|
- private List<Entry> currentDisplayed;
|
|
|
+ private List<EntryStack> currentDisplayed;
|
|
|
private List<Slot> widgets;
|
|
|
private int width, height, page;
|
|
|
private Rectangle rectangle, listArea;
|
|
@@ -115,14 +89,12 @@ public class EntryListWidget extends Widget {
|
|
|
this.height = 0;
|
|
|
this.page = page;
|
|
|
this.lastSearchArgument = Lists.newArrayList();
|
|
|
- scroller.unregisterTick();
|
|
|
- this.scrollVelocity = 0;
|
|
|
}
|
|
|
|
|
|
public static List<String> tryGetItemStackToolTip(ItemStack itemStack, boolean careAboutAdvanced) {
|
|
|
if (!searchBlacklisted.contains(itemStack.getItem()))
|
|
|
try {
|
|
|
- return itemStack.getTooltip(MinecraftClient.getInstance().player, MinecraftClient.getInstance().options.advancedItemTooltips && careAboutAdvanced ? TooltipContext.Default.ADVANCED : TooltipContext.Default.NORMAL).stream().map(Text::asFormattedString).collect(Collectors.toList());
|
|
|
+ return CollectionUtils.map(itemStack.getTooltip(MinecraftClient.getInstance().player, MinecraftClient.getInstance().options.advancedItemTooltips && careAboutAdvanced ? TooltipContext.Default.ADVANCED : TooltipContext.Default.NORMAL), Text::asFormattedString);
|
|
|
} catch (Throwable e) {
|
|
|
e.printStackTrace();
|
|
|
searchBlacklisted.add(itemStack.getItem());
|
|
@@ -130,6 +102,8 @@ public class EntryListWidget extends Widget {
|
|
|
return Collections.singletonList(tryGetItemStackName(itemStack));
|
|
|
}
|
|
|
|
|
|
+ @ToBeRemoved
|
|
|
+ @Deprecated
|
|
|
public static String tryGetEntryName(Entry stack) {
|
|
|
if (stack.getEntryType() == Entry.Type.ITEM)
|
|
|
return tryGetItemStackName(stack.getItemStack());
|
|
@@ -138,11 +112,19 @@ public class EntryListWidget extends Widget {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
+ public static String tryGetEntryStackName(EntryStack stack) {
|
|
|
+ if (stack.getType() == EntryStack.Type.ITEM)
|
|
|
+ return tryGetItemStackName(stack.getItemStack());
|
|
|
+ else if (stack.getType() == EntryStack.Type.FLUID)
|
|
|
+ return tryGetFluidName(stack.getFluid());
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
public static String tryGetFluidName(Fluid fluid) {
|
|
|
Identifier id = Registry.FLUID.getId(fluid);
|
|
|
if (I18n.hasTranslation("block." + id.toString().replaceFirst(":", ".")))
|
|
|
return I18n.translate("block." + id.toString().replaceFirst(":", "."));
|
|
|
- return Stream.of(id.getPath().split("_")).map(StringUtils::capitalize).collect(Collectors.joining(" "));
|
|
|
+ return CollectionUtils.mapAndJoinToString(id.getPath().split("_"), StringUtils::capitalize, " ");
|
|
|
}
|
|
|
|
|
|
public static String tryGetItemStackName(ItemStack stack) {
|
|
@@ -161,7 +143,7 @@ public class EntryListWidget extends Widget {
|
|
|
return "ERROR";
|
|
|
}
|
|
|
|
|
|
- public static boolean filterEntry(Entry entry, List<SearchArgument[]> arguments) {
|
|
|
+ public static boolean filterEntry(EntryStack entry, List<SearchArgument[]> arguments) {
|
|
|
if (arguments.isEmpty())
|
|
|
return true;
|
|
|
AtomicReference<String> mod = new AtomicReference<>(), tooltips = new AtomicReference<>(), name = new AtomicReference<>();
|
|
@@ -170,21 +152,27 @@ public class EntryListWidget extends Widget {
|
|
|
for (SearchArgument argument : arguments1) {
|
|
|
if (argument.getArgumentType() == (SearchArgument.ArgumentType.ALWAYS))
|
|
|
return true;
|
|
|
- if (argument.getArgumentType() == SearchArgument.ArgumentType.MOD)
|
|
|
- if (argument.getFunction(!argument.isInclude()).apply(fillMod(entry, mod).get())) {
|
|
|
+ if (argument.getArgumentType() == SearchArgument.ArgumentType.MOD) {
|
|
|
+ fillMod(entry, mod);
|
|
|
+ if (mod.get() != null && !mod.get().isEmpty() && argument.getFunction(!argument.isInclude()).apply(mod.get())) {
|
|
|
b = false;
|
|
|
break;
|
|
|
}
|
|
|
- if (argument.getArgumentType() == SearchArgument.ArgumentType.TOOLTIP)
|
|
|
- if (argument.getFunction(!argument.isInclude()).apply(fillTooltip(entry, tooltips).get())) {
|
|
|
+ }
|
|
|
+ if (argument.getArgumentType() == SearchArgument.ArgumentType.TOOLTIP) {
|
|
|
+ fillTooltip(entry, tooltips);
|
|
|
+ if (tooltips.get() != null && !tooltips.get().isEmpty() && argument.getFunction(!argument.isInclude()).apply(tooltips.get())) {
|
|
|
b = false;
|
|
|
break;
|
|
|
}
|
|
|
- if (argument.getArgumentType() == SearchArgument.ArgumentType.TEXT)
|
|
|
- if (argument.getFunction(!argument.isInclude()).apply(fillName(entry, name).get())) {
|
|
|
+ }
|
|
|
+ if (argument.getArgumentType() == SearchArgument.ArgumentType.TEXT) {
|
|
|
+ fillName(entry, name);
|
|
|
+ if (name.get() != null && !name.get().isEmpty() && argument.getFunction(!argument.isInclude()).apply(name.get())) {
|
|
|
b = false;
|
|
|
break;
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
if (b)
|
|
|
return true;
|
|
@@ -192,37 +180,31 @@ public class EntryListWidget extends Widget {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- private static AtomicReference<String> fillMod(Entry entry, AtomicReference<String> mod) {
|
|
|
- if (mod.get() == null)
|
|
|
- if (entry.getEntryType() == Entry.Type.ITEM)
|
|
|
- mod.set(ClientHelper.getInstance().getModFromItem(entry.getItemStack().getItem()).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
- else if (entry.getEntryType() == Entry.Type.FLUID)
|
|
|
- mod.set(ClientHelper.getInstance().getModFromIdentifier(Registry.FLUID.getId(entry.getFluid())).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
+ private static AtomicReference<String> fillMod(EntryStack entry, AtomicReference<String> mod) {
|
|
|
+ if (mod.get() == null) {
|
|
|
+ Optional<Identifier> identifier = entry.getIdentifier();
|
|
|
+ if (identifier.isPresent())
|
|
|
+ mod.set(ClientHelper.getInstance().getModFromIdentifier(identifier.get()).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
+ else mod.set("");
|
|
|
+ }
|
|
|
return mod;
|
|
|
}
|
|
|
|
|
|
- private static AtomicReference<String> fillTooltip(Entry entry, AtomicReference<String> mod) {
|
|
|
+ private static AtomicReference<String> fillTooltip(EntryStack entry, AtomicReference<String> mod) {
|
|
|
if (mod.get() == null)
|
|
|
- if (entry.getEntryType() == Entry.Type.ITEM)
|
|
|
- mod.set(tryGetItemStackToolTip(entry.getItemStack(), false).stream().collect(Collectors.joining("")).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
+ if (entry.getType() == EntryStack.Type.ITEM)
|
|
|
+ mod.set(CollectionUtils.joinToString(tryGetItemStackToolTip(entry.getItemStack(), false), "").replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
else
|
|
|
- mod.set(tryGetFluidName(entry.getFluid()).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
+ mod.set(tryGetEntryStackName(entry).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
return mod;
|
|
|
}
|
|
|
|
|
|
- private static AtomicReference<String> fillName(Entry entry, AtomicReference<String> mod) {
|
|
|
+ private static AtomicReference<String> fillName(EntryStack entry, AtomicReference<String> mod) {
|
|
|
if (mod.get() == null)
|
|
|
- if (entry.getEntryType() == Entry.Type.ITEM)
|
|
|
- mod.set(tryGetItemStackName(entry.getItemStack()).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
- else
|
|
|
- mod.set(tryGetFluidName(entry.getFluid()).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
+ mod.set(tryGetEntryStackName(entry).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT));
|
|
|
return mod;
|
|
|
}
|
|
|
|
|
|
- private static void scrollerUnregisterTick() {
|
|
|
- scroller.unregisterTick();
|
|
|
- }
|
|
|
-
|
|
|
public static float getMaxScroll() {
|
|
|
return Math.max(maxScroll - ScreenHelper.getLastOverlay().getEntryListWidget().rectangle.height, 0);
|
|
|
}
|
|
@@ -231,8 +213,43 @@ public class EntryListWidget extends Widget {
|
|
|
return scroll;
|
|
|
}
|
|
|
|
|
|
- public static float getScrollVelocity() {
|
|
|
- return scrollVelocity;
|
|
|
+ public static final float clamp(float v) {
|
|
|
+ return clamp(v, 300f);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static final float clamp(float v, float clampExtension) {
|
|
|
+ return MathHelper.clamp(v, -clampExtension, getMaxScroll() + clampExtension);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void offset(float value, boolean animated) {
|
|
|
+ scrollTo(target + value, animated);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void scrollTo(float value, boolean animated) {
|
|
|
+ scrollTo(value, animated, ClothConfigInitializer.getScrollDuration());
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void scrollTo(float value, boolean animated, long duration) {
|
|
|
+ target = clamp(value);
|
|
|
+
|
|
|
+ if (animated) {
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+ EntryListWidget.duration = duration;
|
|
|
+ } else
|
|
|
+ scroll = target;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void updatePosition(float delta) {
|
|
|
+ target = clamp(target);
|
|
|
+ if (target < 0) {
|
|
|
+ target -= target * (1 - ClothConfigInitializer.getBounceBackMultiplier()) * delta / 3;
|
|
|
+ } else if (target > getMaxScroll()) {
|
|
|
+ target = (float) ((target - getMaxScroll()) * (1 - (1 - ClothConfigInitializer.getBounceBackMultiplier()) * delta / 3) + getMaxScroll());
|
|
|
+ }
|
|
|
+ if (!Precision.almostEquals(scroll, target, Precision.FLOAT_EPSILON))
|
|
|
+ scroll = (float) Interpolation.expoEase(scroll, target, Math.min((System.currentTimeMillis() - start) / ((double) duration), 1));
|
|
|
+ else
|
|
|
+ scroll = target;
|
|
|
}
|
|
|
|
|
|
public int getFullTotalSlotsPerPage() {
|
|
@@ -241,17 +258,12 @@ public class EntryListWidget extends Widget {
|
|
|
|
|
|
@Override
|
|
|
public boolean mouseScrolled(double double_1, double double_2, double double_3) {
|
|
|
- if (!this.scroller.isRegistered())
|
|
|
- this.scroller.registerTick();
|
|
|
if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() && rectangle.contains(double_1, double_2)) {
|
|
|
- if (this.scroll >= 0F && double_3 > 0)
|
|
|
- scrollVelocity -= 24;
|
|
|
- else if (this.scroll <= this.getMaxScroll() && double_3 < 0)
|
|
|
- scrollVelocity += 24;
|
|
|
if (scrollBarAlphaFuture == 0)
|
|
|
scrollBarAlphaFuture = 1f;
|
|
|
if (System.currentTimeMillis() - scrollBarAlphaFutureTime > 300f)
|
|
|
scrollBarAlphaFutureTime = System.currentTimeMillis();
|
|
|
+ offset((float) (ClothConfigInitializer.getScrollStep() * -double_3), true);
|
|
|
return true;
|
|
|
}
|
|
|
return super.mouseScrolled(double_1, double_2, double_3);
|
|
@@ -288,15 +300,15 @@ public class EntryListWidget extends Widget {
|
|
|
if (!widgetScrolled)
|
|
|
scroll = 0;
|
|
|
else {
|
|
|
+ updatePosition(float_1);
|
|
|
page = 0;
|
|
|
ScreenHelper.getLastOverlay().setPage(0);
|
|
|
- Scissors.begin();
|
|
|
- Scissors.scissor(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
|
|
+ ScissorsHandler.INSTANCE.scissor(rectangle);
|
|
|
}
|
|
|
widgets.forEach(widget -> {
|
|
|
if (widgetScrolled) {
|
|
|
- widget.y = (int) (widget.backupY - scroll);
|
|
|
- if (widget.y <= rectangle.y + rectangle.height && widget.y + widget.getBounds().height >= rectangle.y)
|
|
|
+ widget.getBounds().y = (int) (widget.backupY - scroll);
|
|
|
+ if (widget.getBounds().y <= rectangle.y + rectangle.height && widget.getBounds().getMaxY() >= rectangle.y)
|
|
|
widget.render(int_1, int_2, float_1);
|
|
|
} else {
|
|
|
widget.render(int_1, int_2, float_1);
|
|
@@ -331,7 +343,7 @@ public class EntryListWidget extends Widget {
|
|
|
RenderSystem.enableAlphaTest();
|
|
|
RenderSystem.enableTexture();
|
|
|
}
|
|
|
- Scissors.end();
|
|
|
+ ScissorsHandler.INSTANCE.removeLastScissor();
|
|
|
}
|
|
|
RenderSystem.popMatrix();
|
|
|
ClientPlayerEntity player = minecraft.player;
|
|
@@ -345,7 +357,7 @@ public class EntryListWidget extends Widget {
|
|
|
this.widgets = Lists.newCopyOnWriteArrayList();
|
|
|
calculateListSize(rectangle);
|
|
|
if (currentDisplayed.isEmpty() || processSearchTerm)
|
|
|
- currentDisplayed = processSearchTerm(searchTerm, RoughlyEnoughItemsCore.getEntryRegistry().getEntryList(), new ArrayList<>(ScreenHelper.inventoryStacks));
|
|
|
+ currentDisplayed = processSearchTerm(searchTerm, RoughlyEnoughItemsCore.getEntryRegistry().getStacksList(), new ArrayList<>(ScreenHelper.inventoryStacks));
|
|
|
int startX = rectangle.getCenterX() - width * 9;
|
|
|
int startY = rectangle.getCenterY() - height * 9;
|
|
|
this.listArea = new Rectangle(startX, startY, width * 18, height * 18);
|
|
@@ -364,74 +376,16 @@ public class EntryListWidget extends Widget {
|
|
|
j++;
|
|
|
if (j > currentDisplayed.size())
|
|
|
break;
|
|
|
- final Entry entry = currentDisplayed.get(j - 1);
|
|
|
+ final EntryStack stack = currentDisplayed.get(j - 1).copy()
|
|
|
+ .setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE)
|
|
|
+ .setting(EntryStack.Settings.Item.RENDER_OVERLAY, RENDER_EXTRA_CONFIG);
|
|
|
maxScroll = y + 18;
|
|
|
- widgets.add(new Slot(entry, xx, yy, x, y, entry.getEntryType() == Entry.Type.ITEM ? new ItemStackRenderer() {
|
|
|
- @Override
|
|
|
- public ItemStack getItemStack() {
|
|
|
- return entry.getItemStack();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected String getCounts() {
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected boolean renderOverlay() {
|
|
|
- return RoughlyEnoughItemsCore.getConfigManager().getConfig().doesRenderEntryExtraOverlay();
|
|
|
- }
|
|
|
-
|
|
|
- @Nullable
|
|
|
- @Override
|
|
|
- public QueuedTooltip getQueuedTooltip(float delta) {
|
|
|
- ClientPlayerEntity player = minecraft.player;
|
|
|
- if (!ClientHelper.getInstance().isCheating() || player.inventory.getCursorStack().isEmpty())
|
|
|
- return super.getQueuedTooltip(delta);
|
|
|
- return null;
|
|
|
- }
|
|
|
- } : new FluidRenderer() {
|
|
|
- @Override
|
|
|
- public Fluid getFluid() {
|
|
|
- return entry.getFluid();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected List<String> getExtraToolTips(Fluid fluid) {
|
|
|
- if (MinecraftClient.getInstance().options.advancedItemTooltips)
|
|
|
- return Collections.singletonList(Formatting.DARK_GRAY.toString() + Registry.FLUID.getId(fluid).toString());
|
|
|
- return super.getExtraToolTips(fluid);
|
|
|
- }
|
|
|
- }, false, true, true) {
|
|
|
- @Override
|
|
|
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
|
|
- if (isCurrentRendererItem() && containsMouse(mouseX, mouseY)) {
|
|
|
- if (ClientHelper.getInstance().isCheating()) {
|
|
|
- if (getCurrentItemStack() != null && !getCurrentItemStack().isEmpty()) {
|
|
|
- ItemStack cheatedStack = getCurrentItemStack().copy();
|
|
|
- if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemCheatingMode() == ItemCheatingMode.REI_LIKE)
|
|
|
- cheatedStack.setCount(button != 1 ? 1 : cheatedStack.getMaxCount());
|
|
|
- else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemCheatingMode() == ItemCheatingMode.JEI_LIKE)
|
|
|
- cheatedStack.setCount(button != 0 ? 1 : cheatedStack.getMaxCount());
|
|
|
- else
|
|
|
- cheatedStack.setCount(1);
|
|
|
- return ClientHelper.getInstance().tryCheatingStack(cheatedStack);
|
|
|
- }
|
|
|
- } else if (button == 0) {
|
|
|
- return ClientHelper.getInstance().executeRecipeKeyBind(getCurrentItemStack().copy());
|
|
|
- } else if (button == 1)
|
|
|
- return ClientHelper.getInstance().executeUsageKeyBind(getCurrentItemStack().copy());
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
+ widgets.add((Slot) new Slot(xx, yy, x, y).entry(stack).noBackground());
|
|
|
}
|
|
|
if (j > currentDisplayed.size())
|
|
|
break;
|
|
|
}
|
|
|
- EntryListWidget.maxScroll = maxScroll;
|
|
|
- if (!scroller.isRegistered())
|
|
|
- scroller.registerTick();
|
|
|
+ EntryListWidget.maxScroll = Math.max(maxScroll - 18, 0);
|
|
|
}
|
|
|
|
|
|
public int getTotalPage() {
|
|
@@ -471,7 +425,9 @@ public class EntryListWidget extends Widget {
|
|
|
int int_2 = rectangle.height;
|
|
|
int int_3 = MathHelper.clamp((int) ((float) (int_2 * int_2) / (float) maxScroll), 32, int_2 - 8);
|
|
|
double double_6 = Math.max(1.0D, double_5 / (double) (int_2 - int_3));
|
|
|
- scroll = MathHelper.clamp((float) (scroll + double_4 * double_6), 0, height - rectangle.height);
|
|
|
+ scrollBarAlphaFutureTime = System.currentTimeMillis();
|
|
|
+ scrollBarAlphaFuture = 1f;
|
|
|
+ scrollTo(MathHelper.clamp((float) (scroll + double_4 * double_6), 0, height - rectangle.height), false);
|
|
|
}
|
|
|
}
|
|
|
return super.mouseDragged(mouseX, mouseY, int_1, double_3, double_4);
|
|
@@ -486,19 +442,19 @@ public class EntryListWidget extends Widget {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public List<Entry> getCurrentDisplayed() {
|
|
|
+ public List getCurrentDisplayed() {
|
|
|
return currentDisplayed;
|
|
|
}
|
|
|
|
|
|
- private List<Entry> processSearchTerm(String searchTerm, List<Entry> ol, List<ItemStack> inventoryItems) {
|
|
|
+ private List<EntryStack> processSearchTerm(String searchTerm, List<EntryStack> ol, List<ItemStack> inventoryItems) {
|
|
|
lastSearchArgument.clear();
|
|
|
- List<Entry> os = new LinkedList<>(ol);
|
|
|
+ List<EntryStack> os = new LinkedList<>(ol);
|
|
|
if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemListOrdering() != ItemListOrdering.registry)
|
|
|
- os = ol.stream().sorted(ASCENDING_COMPARATOR).collect(Collectors.toList());
|
|
|
+ os.sort(ASCENDING_COMPARATOR);
|
|
|
if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isItemListAscending())
|
|
|
Collections.reverse(os);
|
|
|
String[] splitSearchTerm = StringUtils.splitByWholeSeparatorPreserveAllTokens(searchTerm, "|");
|
|
|
- Arrays.stream(splitSearchTerm).forEachOrdered(s -> {
|
|
|
+ for (String s : splitSearchTerm) {
|
|
|
String[] split = StringUtils.split(s);
|
|
|
SearchArgument[] arguments = new SearchArgument[split.length];
|
|
|
for (int i = 0; i < split.length; i++) {
|
|
@@ -520,20 +476,20 @@ public class EntryListWidget extends Widget {
|
|
|
lastSearchArgument.add(arguments);
|
|
|
else
|
|
|
lastSearchArgument.add(new SearchArgument[]{SearchArgument.ALWAYS});
|
|
|
- });
|
|
|
- List<Entry> stacks = Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<EntryStack> stacks = Collections.emptyList();
|
|
|
if (lastSearchArgument.isEmpty())
|
|
|
stacks = os;
|
|
|
else
|
|
|
- stacks = os.stream().filter(entry -> filterEntry(entry, lastSearchArgument)).collect(Collectors.toList());
|
|
|
+ stacks = CollectionUtils.filter(os, entry -> filterEntry(entry, lastSearchArgument));
|
|
|
if (!RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() || stacks.isEmpty() || inventoryItems.isEmpty())
|
|
|
return Collections.unmodifiableList(stacks);
|
|
|
- List<ItemStack> workingItems = RecipeHelper.getInstance().findCraftableByItems(inventoryItems);
|
|
|
- List<Entry> newList = Lists.newLinkedList();
|
|
|
- for (ItemStack workingItem : workingItems) {
|
|
|
- Optional<Entry> any = stacks.stream().filter(i -> i.getItemStack() != null && i.getItemStack().isItemEqualIgnoreDamage(workingItem)).findAny();
|
|
|
- if (any.isPresent())
|
|
|
- newList.add(any.get());
|
|
|
+ List<EntryStack> workingItems = RecipeHelper.getInstance().findCraftableEntriesByItems(inventoryItems);
|
|
|
+ List<EntryStack> newList = Lists.newLinkedList();
|
|
|
+ for (EntryStack workingItem : workingItems) {
|
|
|
+ EntryStack any = CollectionUtils.findFirstOrNullEquals(stacks, workingItem);
|
|
|
+ if (any != null)
|
|
|
+ newList.add(any);
|
|
|
}
|
|
|
if (newList.isEmpty())
|
|
|
return Collections.unmodifiableList(stacks);
|
|
@@ -596,27 +552,21 @@ public class EntryListWidget extends Widget {
|
|
|
return widgets;
|
|
|
}
|
|
|
|
|
|
- public class Slot extends SlotWidget {
|
|
|
+ private class Slot extends EntryWidget {
|
|
|
private final int backupY;
|
|
|
private int xx, yy;
|
|
|
- private Entry entry;
|
|
|
|
|
|
- public Slot(Entry entry, int xx, int yy, int x, int y, Renderer renderer, boolean drawBackground, boolean showToolTips, boolean clickToMoreRecipes) {
|
|
|
- super(x, y, renderer, drawBackground, showToolTips, clickToMoreRecipes);
|
|
|
+ public Slot(int xx, int yy, int x, int y) {
|
|
|
+ super(x, y);
|
|
|
this.xx = xx;
|
|
|
this.yy = yy;
|
|
|
this.backupY = y;
|
|
|
- this.entry = entry;
|
|
|
}
|
|
|
|
|
|
public int getBackupY() {
|
|
|
return backupY;
|
|
|
}
|
|
|
|
|
|
- public Entry getEntry() {
|
|
|
- return entry;
|
|
|
- }
|
|
|
-
|
|
|
public int getXx() {
|
|
|
return xx;
|
|
|
}
|
|
@@ -629,6 +579,33 @@ public class EntryListWidget extends Widget {
|
|
|
public boolean containsMouse(double mouseX, double mouseY) {
|
|
|
return super.containsMouse(mouseX, mouseY) && rectangle.contains(mouseX, mouseY);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void queueTooltip(int mouseX, int mouseY, float delta) {
|
|
|
+ ClientPlayerEntity player = minecraft.player;
|
|
|
+ if (!ClientHelper.getInstance().isCheating() || player.inventory.getCursorStack().isEmpty())
|
|
|
+ super.queueTooltip(mouseX, mouseY, delta);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
|
|
+ if (!interactable)
|
|
|
+ return super.mouseClicked(mouseX, mouseY, button);
|
|
|
+ if (containsMouse(mouseX, mouseY) && ClientHelper.getInstance().isCheating()) {
|
|
|
+ EntryStack entry = getCurrentEntry().copy();
|
|
|
+ if (entry.getType() == EntryStack.Type.ITEM) {
|
|
|
+ if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemCheatingMode() == ItemCheatingMode.REI_LIKE)
|
|
|
+ entry.setAmount(button != 1 ? 1 : entry.getItemStack().getMaxCount());
|
|
|
+ else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemCheatingMode() == ItemCheatingMode.JEI_LIKE)
|
|
|
+ entry.setAmount(button != 0 ? 1 : entry.getItemStack().getMaxCount());
|
|
|
+ else
|
|
|
+ entry.setAmount(1);
|
|
|
+ }
|
|
|
+ ClientHelper.getInstance().tryCheatingEntry(entry);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return super.mouseClicked(mouseX, mouseY, button);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|