aboutsummaryrefslogtreecommitdiff
path: root/fabric/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-06-27 20:36:30 +0800
committershedaniel <daniel@shedaniel.me>2021-06-27 20:36:49 +0800
commit5d8cca18abfb2538404b07a886edb854c9279952 (patch)
tree55764af31c2350bda10561a85acf7c8358db704f /fabric/src/main/java
parent4cbdc5d77a1406ef6d8b350ddedce987cbed3647 (diff)
downloadRoughlyEnoughItems-5d8cca18abfb2538404b07a886edb854c9279952.tar.gz
RoughlyEnoughItems-5d8cca18abfb2538404b07a886edb854c9279952.tar.bz2
RoughlyEnoughItems-5d8cca18abfb2538404b07a886edb854c9279952.zip
Fix alignment of items, fix #570
Diffstat (limited to 'fabric/src/main/java')
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java29
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java47
2 files changed, 48 insertions, 28 deletions
diff --git a/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java
index 410b31e21..e44cf3d09 100644
--- a/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java
+++ b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java
@@ -23,28 +23,18 @@
package me.shedaniel.rei.fabric;
-import com.google.common.base.Suppliers;
import com.google.common.collect.Iterables;
import me.shedaniel.rei.RoughlyEnoughItemsInitializer;
import me.shedaniel.rei.RoughlyEnoughItemsState;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.common.plugins.*;
-import me.shedaniel.rei.impl.ClientInternals;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
-import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
-import net.minecraft.world.inventory.tooltip.TooltipComponent;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.Collection;
-import java.util.List;
-import java.util.function.BiConsumer;
import java.util.function.Consumer;
-import java.util.function.Supplier;
public class PluginDetectorImpl {
private static <P extends REIPlugin<?>> void loadPlugin(Class<? extends P> pluginClass, Consumer<? super REIPluginProvider<P>> consumer) {
@@ -60,7 +50,7 @@ public class PluginDetectorImpl {
try {
REIPluginProvider<P> plugin = container.getEntrypoint();
if (pluginClass.isAssignableFrom(plugin.getPluginProviderClass())) {
- consumer.accept(new REIPluginProvider<>() {
+ consumer.accept(new REIPluginProvider<P>() {
@Override
public Collection<P> provide() {
return plugin.provide();
@@ -115,22 +105,5 @@ public class PluginDetectorImpl {
@Environment(EnvType.CLIENT)
public static void detectClientPlugins() {
loadPlugin(REIClientPlugin.class, ((PluginView<REIClientPlugin>) PluginManager.getClientInstance())::registerPlugin);
- Supplier<Method> method = Suppliers.memoize(() -> {
- String methodName = FabricLoader.getInstance().getMappingResolver().mapMethodName("intermediary", "net.minecraft.class_437", "method_32635", "(Ljava/util/List;Lnet/minecraft/class_5632;)V");
- try {
- Method declaredMethod = Screen.class.getDeclaredMethod(methodName, List.class, TooltipComponent.class);
- if (declaredMethod != null) declaredMethod.setAccessible(true);
- return declaredMethod;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- }
- });
- ClientInternals.attachInstance((BiConsumer<List<ClientTooltipComponent>, TooltipComponent>) (lines, component) -> {
- try {
- method.get().invoke(null, lines, component);
- } catch (IllegalAccessException | InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }, "clientTooltipComponentProvider");
}
}
diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java b/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java
new file mode 100644
index 000000000..e38481723
--- /dev/null
+++ b/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java
@@ -0,0 +1,47 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.client.gui.fabric;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.locale.Language;
+import net.minecraft.network.chat.Style;
+
+import java.util.stream.Collectors;
+
+public class ScreenOverlayImplImpl {
+ public static void renderTooltipInner(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY) {
+ matrices.pushPose();
+ matrices.translate(0, 0, 500);
+ screen.renderTooltip(matrices, tooltip.getText().stream()
+ .flatMap(component -> {
+ return Minecraft.getInstance().font.getSplitter().splitLines(component, 100000, Style.EMPTY).stream()
+ .map(Language.getInstance()::getVisualOrder);
+ })
+ .collect(Collectors.toList()), mouseX, mouseY);
+ matrices.popPose();
+ }
+}