diff options
Diffstat (limited to 'api/src/main/java/me')
11 files changed, 152 insertions, 58 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java index 085eb772b..43be06845 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java @@ -28,6 +28,7 @@ import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.impl.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.world.item.Item; import net.minecraft.world.item.TooltipFlag; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -35,24 +36,24 @@ import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) @ApiStatus.NonExtendable public interface TooltipContext { - static TooltipContext of() { - return TooltipContext.of(new Point()); + static TooltipContext of(Item.TooltipContext vanillaContext) { + return TooltipContext.of(new Point(), vanillaContext); } - static TooltipContext of(Point point) { - return TooltipContext.of(point, null); + static TooltipContext of(Point point, Item.TooltipContext vanillaContext) { + return TooltipContext.of(point, vanillaContext, null); } - static TooltipContext of(Point point, @Nullable TooltipFlag flag) { - return TooltipContext.of(point, flag, false); + static TooltipContext of(Point point, Item.TooltipContext vanillaContext, @Nullable TooltipFlag flag) { + return TooltipContext.of(point, vanillaContext, flag, false); } - static TooltipContext of(Point point, @Nullable TooltipFlag flag, boolean isSearch) { - return ClientInternals.createTooltipContext(point, flag, isSearch); + static TooltipContext of(Point point, Item.TooltipContext vanillaContext, @Nullable TooltipFlag flag, boolean isSearch) { + return ClientInternals.createTooltipContext(point, flag, isSearch, vanillaContext); } - static TooltipContext ofMouse() { - return TooltipContext.of(PointHelper.ofMouse()); + static TooltipContext ofMouse(Item.TooltipContext vanillaContext) { + return TooltipContext.of(PointHelper.ofMouse(), vanillaContext); } TooltipFlag getFlag(); @@ -60,4 +61,6 @@ public interface TooltipContext { Point getPoint(); boolean isSearch(); + + Item.TooltipContext vanillaContext(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java index ccd395071..45a31d515 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java @@ -40,6 +40,7 @@ import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.item.Item; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import org.joml.Matrix4f; @@ -98,7 +99,7 @@ public final class Widgets { Point mouse = new Point(mouseX, mouseY); Tooltip tooltip = tooltipSupplier.apply(mouse); if (tooltip != null) { - tooltip = Tooltip.from(TooltipContext.ofMouse().getPoint(), tooltip.entries()); + tooltip = Tooltip.from(TooltipContext.ofMouse(Item.TooltipContext.EMPTY).getPoint(), tooltip.entries()); tooltip.queue(); } }); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java index e1d9ab421..ceaee76e6 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java @@ -35,6 +35,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.resources.ResourceLocation; import org.joml.Matrix3f; import org.joml.Matrix4f; +import org.joml.Vector3f; @Environment(EnvType.CLIENT) public class SpriteRenderer { @@ -240,37 +241,38 @@ public class SpriteRenderer { this.consumer = consumers.getBuffer(layer); - this.consumer.vertex(this.model, x, y + nSY, z1) + normal(this.consumer.vertex(this.model, x, y + nSY, z1) .color(this.r, this.g, this.b, this.a) .uv(this.uStart, this.vEnd - dY) .overlayCoords(this.u, this.v) - .uv2(this.l) - .normal(this.normal, this.nX, this.nY, this.nZ) + .uv2(this.l), this.normal, this.nX, this.nY, this.nZ) .endVertex(); - this.consumer.vertex(this.model, x + nSX, y + nSY, z1) + normal(this.consumer.vertex(this.model, x + nSX, y + nSY, z1) .color(this.r, this.g, this.b, this.a) .uv(this.uEnd - dX, this.vEnd - dY) .overlayCoords(this.u, this.v) - .uv2(this.l) - .normal(this.normal, this.nX, this.nY, this.nZ) + .uv2(this.l), this.normal, this.nX, this.nY, this.nZ) .endVertex(); - this.consumer.vertex(this.model, x + nSX, y, z1) + normal(this.consumer.vertex(this.model, x + nSX, y, z1) .color(this.r, this.g, this.b, this.a) .uv(this.uEnd - dX, this.vStart) .overlayCoords(this.u, this.v) - .uv2(this.l) - .normal(this.normal, this.nX, this.nY, this.nZ) + .uv2(this.l), this.normal, this.nX, this.nY, this.nZ) .endVertex(); - this.consumer.vertex(this.model, x, y, z1) + normal(this.consumer.vertex(this.model, x, y, z1) .color(this.r, this.g, this.b, this.a) .uv(this.uStart, this.vStart) .overlayCoords(this.u, this.v) - .uv2(this.l) - .normal(this.normal, this.nX, this.nY, this.nZ) + .uv2(this.l), this.normal, this.nX, this.nY, this.nZ) .endVertex(); } } } + + private static VertexConsumer normal(VertexConsumer consumer, Matrix3f var1, float var2, float var3, float var4) { + Vector3f var5 = var1.transform(new Vector3f(var2, var3, var4)); + return consumer.normal(var5.x(), var5.y(), var5.z()); + } } }
\ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java index 03dfc162b..5e24c6ccf 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java @@ -25,8 +25,8 @@ package me.shedaniel.rei.api.common.entry.comparison; import dev.architectury.fluid.FluidStack; import me.shedaniel.rei.impl.Internals; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponentType; import net.minecraft.world.item.ItemStack; import java.util.Objects; @@ -47,40 +47,38 @@ public interface EntryComparator<T> { } /** - * Creates an {@link EntryComparator} that compares the {@link ItemStack}'s NBT. + * Creates an {@link EntryComparator} that compares the {@link ItemStack}'s components. * - * @return an {@link EntryComparator} that compares the {@link ItemStack}'s NBT + * @return an {@link EntryComparator} that compares the {@link ItemStack}'s components */ - static EntryComparator<ItemStack> itemNbt() { - EntryComparator<Tag> nbtHasher = nbt("Count"); + static EntryComparator<ItemStack> itemComponents() { + EntryComparator<DataComponentMap> componentHasher = component(); return (context, stack) -> { - CompoundTag tag = stack.getTag(); - return tag == null ? 0L : nbtHasher.hash(context, tag); + return componentHasher.hash(context, stack.getComponents()); }; } /** - * Creates an {@link EntryComparator} that compares the {@link FluidStack}'s NBT. + * Creates an {@link EntryComparator} that compares the {@link FluidStack}'s components. * - * @return an {@link EntryComparator} that compares the {@link FluidStack}'s NBT + * @return an {@link EntryComparator} that compares the {@link FluidStack}'s components */ - static EntryComparator<FluidStack> fluidNbt() { - EntryComparator<Tag> nbtHasher = nbt("Amount"); + static EntryComparator<FluidStack> fluidComponents() { + EntryComparator<DataComponentMap> componentHasher = component(); return (context, stack) -> { - CompoundTag tag = stack.getTag(); - return tag == null ? 0L : nbtHasher.hash(context, tag); + return 0L; }; } /** - * Creates an {@link EntryComparator} that compares the nbt, but + * Creates an {@link EntryComparator} that compares the components, but * ignoring some given keys. * * @param ignoredKeys the keys to ignore - * @return an {@link EntryComparator} that compares the nbt + * @return an {@link EntryComparator} that compares the components */ - static EntryComparator<Tag> nbt(String... ignoredKeys) { - return Internals.getNbtHasher(ignoredKeys); + static EntryComparator<DataComponentMap> component(DataComponentType<?>... ignoredKeys) { + return Internals.getComponentHasher(ignoredKeys); } /** diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/FluidComparatorRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/FluidComparatorRegistry.java index 643ff7d91..6f6968c0e 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/FluidComparatorRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/FluidComparatorRegistry.java @@ -46,7 +46,7 @@ public interface FluidComparatorRegistry extends EntryComparatorRegistry<FluidSt * @param fluid the fluid to compare */ default void registerNbt(Fluid fluid) { - register(EntryComparator.fluidNbt(), fluid); + register(EntryComparator.fluidComponents(), fluid); } /** @@ -55,6 +55,6 @@ public interface FluidComparatorRegistry extends EntryComparatorRegistry<FluidSt * @param fluids the fluids to compare */ default void registerNbt(Fluid... fluids) { - register(EntryComparator.fluidNbt(), fluids); + register(EntryComparator.fluidComponents(), fluids); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparatorRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparatorRegistry.java index fd9ed4f5c..2aea3e166 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparatorRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ItemComparatorRegistry.java @@ -41,20 +41,20 @@ public interface ItemComparatorRegistry extends EntryComparatorRegistry<ItemStac } /** - * Registers an item to compare via its nbt. + * Registers an item to compare via its components. * * @param item the item to compare */ - default void registerNbt(Item item) { - register(EntryComparator.itemNbt(), item); + default void registerComponents(Item item) { + register(EntryComparator.itemComponents(), item); } /** - * Registers items to compare via their nbt. + * Registers items to compare via their components. * * @param items the items to compare */ - default void registerNbt(Item... items) { - register(EntryComparator.itemNbt(), items); + default void registerComponents(Item... items) { + register(EntryComparator.itemComponents(), items); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/RecipeFinder.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/RecipeFinder.java index dee0825db..88283efdf 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/RecipeFinder.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/RecipeFinder.java @@ -26,6 +26,7 @@ package me.shedaniel.rei.api.common.transfer; import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.ints.*; import net.minecraft.core.NonNullList; +import net.minecraft.core.component.DataComponents; import net.minecraft.world.entity.player.StackedContents; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; @@ -47,7 +48,7 @@ public class RecipeFinder { } public void addNormalItem(ItemStack stack) { - if (!stack.isDamaged() && !stack.isEnchanted() && !stack.hasCustomHoverName()) { + if (!stack.isDamaged() && !stack.isEnchanted() && !stack.has(DataComponents.CUSTOM_NAME)) { this.addItem(stack); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/DumpHandler.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/DumpHandler.java index 776f34498..72a8ed55e 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/DumpHandler.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/DumpHandler.java @@ -55,6 +55,6 @@ public interface DumpHandler<T extends AbstractContainerMenu, D extends Display> } static boolean canStackAddMore(ItemStack existingStack, ItemStack stack) { - return !existingStack.isEmpty() && ItemStack.isSameItemSameTags(existingStack, stack) && existingStack.isStackable() && existingStack.getCount() + stack.getCount() <= existingStack.getMaxStackSize(); + return !existingStack.isEmpty() && ItemStack.isSameItemSameComponents(existingStack, stack) && existingStack.isStackable() && existingStack.getCount() + stack.getCount() <= existingStack.getMaxStackSize(); } } diff --git a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java index 1ef71f0e8..b366ee2ef 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java @@ -47,14 +47,16 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; +import net.minecraft.data.models.blockstates.PropertyDispatch; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import org.apache.commons.lang3.function.TriFunction; +import org.apache.commons.io.function.IOQuadFunction; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import org.joml.Matrix4f; @@ -83,7 +85,7 @@ public final class ClientInternals { private static Function<Boolean, ClickArea.Result> clickAreaHandlerResult = (result) -> throwNotSetup(); private static BiConsumer<List<ClientTooltipComponent>, TooltipComponent> clientTooltipComponentProvider = (tooltip, result) -> throwNotSetup(); private static BiFunction<@Nullable Point, Collection<Tooltip.Entry>, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); - private static TriFunction<Point, @Nullable TooltipFlag, Boolean, TooltipContext> tooltipContextProvider = (point, texts, search) -> throwNotSetup(); + private static PropertyDispatch.QuadFunction<Point, @Nullable TooltipFlag, Boolean, Item.TooltipContext, TooltipContext> tooltipContextProvider = (point, texts, search, context) -> throwNotSetup(); private static Function<Object, Tooltip.Entry> tooltipEntryProvider = (component) -> throwNotSetup(); private static Supplier<List<String>> jeiCompatMods = ClientInternals::throwNotSetup; private static Supplier<Object> builtinClientPlugin = ClientInternals::throwNotSetup; @@ -146,8 +148,8 @@ public final class ClientInternals { return tooltipProvider.apply(point, texts); } - public static TooltipContext createTooltipContext(Point point, @Nullable TooltipFlag flag, boolean isSearch) { - return tooltipContextProvider.apply(point, flag, isSearch); + public static TooltipContext createTooltipContext(Point point, @Nullable TooltipFlag flag, boolean isSearch, Item.TooltipContext context) { + return tooltipContextProvider.apply(point, flag, isSearch, context); } public static Tooltip.Entry createTooltipEntry(Object component) { diff --git a/api/src/main/java/me/shedaniel/rei/impl/Internals.java b/api/src/main/java/me/shedaniel/rei/impl/Internals.java index bcbfcc7fb..d083a3183 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/Internals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/Internals.java @@ -36,7 +36,8 @@ import me.shedaniel.rei.api.common.plugins.REIServerPlugin; import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry; import me.shedaniel.rei.impl.common.InternalLogger; import net.minecraft.core.RegistryAccess; -import net.minecraft.nbt.Tag; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponentType; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Unit; import org.jetbrains.annotations.ApiStatus; @@ -107,7 +108,7 @@ public final class Internals { return serverPluginManager.get(); } - public static EntryComparator<Tag> getNbtHasher(String[] ignoredKeys) { + public static EntryComparator<DataComponentMap> getComponentHasher(DataComponentType<?>[] ignoredKeys) { return nbtHasherProvider.get().provide(ignoredKeys); } @@ -144,6 +145,6 @@ public final class Internals { } public interface NbtHasherProvider { - EntryComparator<Tag> provide(String... ignoredKeys); + EntryComparator<DataComponentMap> provide(DataComponentType<?>... ignoredKeys); } } diff --git a/api/src/main/java/me/shedaniel/rei/impl/common/InternalRegistryAccess.java b/api/src/main/java/me/shedaniel/rei/impl/common/InternalRegistryAccess.java new file mode 100644 index 000000000..2f1354c4a --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/common/InternalRegistryAccess.java @@ -0,0 +1,86 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.common; + +import dev.architectury.platform.Platform; +import dev.architectury.utils.Env; +import dev.architectury.utils.GameInstance; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; +import org.jetbrains.annotations.ApiStatus; + +import java.lang.ref.WeakReference; +import java.util.function.Supplier; + +@ApiStatus.Internal +public final class InternalRegistryAccess implements Supplier<RegistryAccess> { + private static final InternalRegistryAccess INSTANCE = new InternalRegistryAccess(); + private WeakReference<RegistryAccess> registryAccess; + private boolean warned; + + public static InternalRegistryAccess getInstance() { + return INSTANCE; + } + + @Override + public RegistryAccess get() { + RegistryAccess access = this.registryAccess == null ? null : this.registryAccess.get(); + if (access != null) { + return access; + } + + if (Platform.getEnvironment() == Env.CLIENT) { + access = getFromClient(); + } else if (GameInstance.getServer() != null) { + access = GameInstance.getServer().registryAccess(); + } + + if (access == null && !this.warned) { + this.warned = true; + + new NullPointerException("Cannot get registry access!").printStackTrace(); + InternalLogger.getInstance().warn("Cannot get registry access!"); + return RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY); + } + + return access; + } + + @Environment(EnvType.CLIENT) + private static RegistryAccess getFromClient() { + if (Minecraft.getInstance().level != null) { + return Minecraft.getInstance().level.registryAccess(); + } else if (Minecraft.getInstance().getConnection() != null) { + return Minecraft.getInstance().getConnection().registryAccess(); + } else if (Minecraft.getInstance().gameMode != null) { + // Sometimes the packet is sent way too fast and is between the connection and the level, better safe than sorry + return Minecraft.getInstance().gameMode.connection.registryAccess(); + } + + return null; + } +} |
