diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-06-22 01:47:32 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-06-22 01:47:32 +0800 |
| commit | 927a4af76ec3c74dc83c38b5b46d105a933bb48a (patch) | |
| tree | cffa99dbeb9b56d53e0dfeacdcb857b2368a391d /runtime/src/main/java/me/shedaniel | |
| parent | 0d1886cd3a85e7829646b666c36b35cf3321f1b0 (diff) | |
| download | RoughlyEnoughItems-927a4af76ec3c74dc83c38b5b46d105a933bb48a.tar.gz RoughlyEnoughItems-927a4af76ec3c74dc83c38b5b46d105a933bb48a.tar.bz2 RoughlyEnoughItems-927a4af76ec3c74dc83c38b5b46d105a933bb48a.zip | |
Fix #558
Diffstat (limited to 'runtime/src/main/java/me/shedaniel')
5 files changed, 125 insertions, 40 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java index 995dbfe5a..a70f7c5d2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java @@ -32,14 +32,16 @@ import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.ClientHelper; -import me.shedaniel.rei.api.client.gui.AbstractRenderer; +import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.impl.client.util.CrashReportUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.CrashReport; import net.minecraft.CrashReportCategory; +import net.minecraft.ReportedException; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -53,9 +55,23 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; @ApiStatus.Internal -public abstract class AbstractEntryStack<A> extends AbstractRenderer implements EntryStack<A> { +public abstract class AbstractEntryStack<A> implements EntryStack<A>, Renderer { private static final Short2ObjectMap<Object> EMPTY_SETTINGS = Short2ObjectMaps.emptyMap(); private Short2ObjectMap<Object> settings = null; + @Environment(EnvType.CLIENT) + private int blitOffset; + + @Override + @Environment(EnvType.CLIENT) + public int getZ() { + return blitOffset; + } + + @Override + @Environment(EnvType.CLIENT) + public void setZ(int z) { + this.blitOffset = z; + } @Override public <T> EntryStack<A> setting(Settings<T> settings, T value) { @@ -150,24 +166,36 @@ public abstract class AbstractEntryStack<A> extends AbstractRenderer implements @Override public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { - this.getRenderer().render(this, matrices, bounds, mouseX, mouseY, delta); + try { + this.getRenderer().render(this, matrices, bounds, mouseX, mouseY, delta); + } catch (Throwable throwable) { + CrashReport report = CrashReportUtils.essential(throwable, "Rendering entry"); + CrashReportUtils.renderer(report, this); + throw new ReportedException(report); + } } @Override @Nullable public Tooltip getTooltip(Point mouse, boolean appendModName) { - Mutable<Tooltip> tooltip = new MutableObject<>(getRenderer().<A>cast().getTooltip(this, mouse)); - if (tooltip.getValue() == null) return null; - tooltip.getValue().addAllTexts(get(Settings.TOOLTIP_APPEND_EXTRA).apply(this)); - tooltip.setValue(get(Settings.TOOLTIP_PROCESSOR).apply(this, tooltip.getValue())); - if (tooltip.getValue() == null) return null; - if (appendModName) { - ResourceLocation location = getIdentifier(); - if (location != null) { - ClientHelper.getInstance().appendModIdToTooltips(tooltip.getValue(), location.getNamespace()); + try { + Mutable<Tooltip> tooltip = new MutableObject<>(getRenderer().<A>cast().getTooltip(this, mouse)); + if (tooltip.getValue() == null) return null; + tooltip.getValue().addAllTexts(get(Settings.TOOLTIP_APPEND_EXTRA).apply(this)); + tooltip.setValue(get(Settings.TOOLTIP_PROCESSOR).apply(this, tooltip.getValue())); + if (tooltip.getValue() == null) return null; + if (appendModName) { + ResourceLocation location = getIdentifier(); + if (location != null) { + ClientHelper.getInstance().appendModIdToTooltips(tooltip.getValue(), location.getNamespace()); + } } + return tooltip.getValue(); + } catch (Throwable throwable) { + CrashReport report = CrashReportUtils.essential(throwable, "Getting tooltips"); + CrashReportUtils.renderer(report, this); + throw new ReportedException(report); } - return tooltip.getValue(); } @Override @@ -205,7 +233,7 @@ public abstract class AbstractEntryStack<A> extends AbstractRenderer implements @Override public void fillCrashReport(CrashReport report, CrashReportCategory category) { - super.fillCrashReport(report, category); + EntryStack.super.fillCrashReport(report, category); category.setDetail("Entry type", () -> String.valueOf(getType().getId())); category.setDetail("Is empty", () -> String.valueOf(isEmpty())); category.setDetail("Entry identifier", () -> String.valueOf(getIdentifier())); diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java index 23248d2fa..ec1ffd2d2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java @@ -25,7 +25,6 @@ package me.shedaniel.rei.plugin.client; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import dev.architectury.event.CompoundEventResult; import dev.architectury.fluid.FluidStack; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -49,9 +48,7 @@ import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry; import me.shedaniel.rei.api.client.util.ClientEntryStacks; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; -import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; @@ -59,8 +56,6 @@ import me.shedaniel.rei.impl.client.gui.screen.AbstractDisplayViewingScreen; import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; import me.shedaniel.rei.impl.client.gui.widget.FavoritesListWidget; import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler; -import me.shedaniel.rei.plugin.client.entry.FluidEntryDefinition; -import me.shedaniel.rei.plugin.client.entry.ItemEntryDefinition; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.screens.Screen; @@ -74,29 +69,11 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.Collections; -import java.util.Optional; import java.util.function.Function; -import java.util.stream.Stream; @Environment(EnvType.CLIENT) @ApiStatus.Internal public class DefaultClientRuntimePlugin implements REIClientPlugin { - public static final ResourceLocation PLUGIN = new ResourceLocation("roughlyenoughitems", "default_runtime_plugin"); - - @Override - public void registerEntryTypes(EntryTypeRegistry registry) { - registry.register(VanillaEntryTypes.ITEM, new ItemEntryDefinition()); - registry.register(VanillaEntryTypes.FLUID, new FluidEntryDefinition()); - - registry.registerBridge(VanillaEntryTypes.ITEM, VanillaEntryTypes.FLUID, input -> { - Optional<Stream<EntryStack<FluidStack>>> stream = FluidSupportProvider.getInstance().itemToFluids(input); - if (!stream.isPresent()) { - return CompoundEventResult.pass(); - } - return CompoundEventResult.interruptTrue(stream.get()); - }); - } - @Override public void registerEntries(EntryRegistry registry) { if (ClientHelperImpl.getInstance().isAprilFools.get()) { diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java index 90e1da0bd..6ddaba0ba 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java @@ -84,7 +84,14 @@ public class FluidEntryDefinition implements EntryDefinition<FluidStack>, EntryS private EntryRenderer<FluidStack> renderer; public FluidEntryDefinition() { - EnvExecutor.runInEnv(Env.CLIENT, () -> () -> renderer = new FluidEntryRenderer()); + EnvExecutor.runInEnv(Env.CLIENT, () -> () -> Client.init(this)); + } + + @Environment(EnvType.CLIENT) + private static class Client { + private static void init(FluidEntryDefinition definition) { + definition.renderer = new FluidEntryRenderer(); + } } @Override @@ -189,6 +196,7 @@ public class FluidEntryDefinition implements EntryDefinition<FluidStack>, EntryS category.setDetail("Fluid NBT", () -> String.valueOf(stack.getTag())); } + @Environment(EnvType.CLIENT) public static class FluidEntryRenderer extends AbstractEntryRenderer<FluidStack> implements BatchedEntryRenderer<FluidStack, TextureAtlasSprite> { private static final Supplier<TextureAtlasSprite> MISSING_SPRITE = Suppliers.memoize(() -> { TextureAtlas atlas = Minecraft.getInstance().getModelManager().getAtlas(TextureAtlas.LOCATION_BLOCKS); diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java index 95dc8b3e4..920cfca92 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java @@ -80,7 +80,14 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer private EntryRenderer<ItemStack> renderer; public ItemEntryDefinition() { - EnvExecutor.runInEnv(Env.CLIENT, () -> () -> renderer = new ItemEntryRenderer()); + EnvExecutor.runInEnv(Env.CLIENT, () -> () -> Client.init(this)); + } + + @Environment(EnvType.CLIENT) + private static class Client { + private static void init(ItemEntryDefinition definition) { + definition.renderer = definition.new ItemEntryRenderer(); + } } @Override @@ -188,6 +195,7 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer return collection == null ? Collections.emptyList() : collection.getMatchingTags(value.getItem()); } + @Environment(EnvType.CLIENT) private List<Component> tryGetItemStackToolTip(EntryStack<ItemStack> entry, ItemStack value, boolean careAboutAdvanced) { if (!SEARCH_BLACKLISTED.contains(value.getItem())) try { @@ -335,7 +343,11 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer if (!components.isEmpty()) { tooltip.add(components.get(0)); } - component.ifPresent(tooltipComponent -> tooltip.add(ClientTooltipComponent.create(tooltipComponent))); + try { + component.ifPresent(tooltipComponent -> tooltip.add(ClientTooltipComponent.create(tooltipComponent))); + } catch (IllegalArgumentException exception) { + throw new IllegalArgumentException("Failed to add tooltip component! " + component.orElse(null), exception); + } for (int i = 1; i < components.size(); i++) { tooltip.add(components.get(i)); } diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/common/DefaultRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/common/DefaultRuntimePlugin.java new file mode 100644 index 000000000..103da1937 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/common/DefaultRuntimePlugin.java @@ -0,0 +1,60 @@ +/* + * 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.plugin.common; + +import dev.architectury.event.CompoundEventResult; +import dev.architectury.fluid.FluidStack; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; +import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; +import me.shedaniel.rei.api.common.plugins.REIServerPlugin; +import me.shedaniel.rei.plugin.client.entry.FluidEntryDefinition; +import me.shedaniel.rei.plugin.client.entry.ItemEntryDefinition; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Optional; +import java.util.stream.Stream; + +@ApiStatus.Internal +public class DefaultRuntimePlugin implements REIServerPlugin { + public static final ResourceLocation PLUGIN = new ResourceLocation("roughlyenoughitems", "default_runtime_plugin"); + + @Override + public void registerEntryTypes(EntryTypeRegistry registry) { + registry.register(VanillaEntryTypes.ITEM, new ItemEntryDefinition()); + registry.register(VanillaEntryTypes.FLUID, new FluidEntryDefinition()); + + registry.registerBridge(VanillaEntryTypes.ITEM, VanillaEntryTypes.FLUID, input -> { + Optional<Stream<EntryStack<FluidStack>>> stream = FluidSupportProvider.getInstance().itemToFluids(input); + if (!stream.isPresent()) { + return CompoundEventResult.pass(); + } + return CompoundEventResult.interruptTrue(stream.get()); + }); + } +} |
