From 05069aa62b09f02a8cd6e526ec58a30347a56500 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 27 Jul 2022 23:25:27 +0800 Subject: WIP Module --- .../.gradle/loom-cache/launch.cfg | 14 + .../.gradle/loom-cache/log4j.xml | 63 ++++ .../.gradle/loom-cache/remapClasspath.txt | 1 + ...lt-runtime-plugin-transformProductionFabric.jar | Bin 0 -> 166 bytes ...ult-runtime-plugin-transformProductionForge.jar | Bin 0 -> 166 bytes .../plugin/client/entry/FluidEntryDefinition.java | 316 +++++++++++++++++ .../plugin/client/entry/ItemEntryDefinition.java | 382 +++++++++++++++++++++ .../common/runtime/DefaultRuntimePlugin.java | 56 +++ .../shedaniel/rei/plugin/test/REITestPlugin.java | 105 ++++++ 9 files changed, 937 insertions(+) create mode 100644 runtime-engine/default-runtime-plugin/.gradle/loom-cache/launch.cfg create mode 100644 runtime-engine/default-runtime-plugin/.gradle/loom-cache/log4j.xml create mode 100644 runtime-engine/default-runtime-plugin/.gradle/loom-cache/remapClasspath.txt create mode 100644 runtime-engine/default-runtime-plugin/build/libs/default-runtime-plugin-transformProductionFabric.jar create mode 100644 runtime-engine/default-runtime-plugin/build/libs/default-runtime-plugin-transformProductionForge.jar create mode 100644 runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java create mode 100644 runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java create mode 100644 runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java create mode 100644 runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java (limited to 'runtime-engine/default-runtime-plugin') diff --git a/runtime-engine/default-runtime-plugin/.gradle/loom-cache/launch.cfg b/runtime-engine/default-runtime-plugin/.gradle/loom-cache/launch.cfg new file mode 100644 index 000000000..78cd94430 --- /dev/null +++ b/runtime-engine/default-runtime-plugin/.gradle/loom-cache/launch.cfg @@ -0,0 +1,14 @@ +commonProperties + fabric.development=true + fabric.remapClasspathFile=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/runtime-engine/default-runtime-plugin/.gradle/loom-cache/remapClasspath.txt + log4j.configurationFile=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/runtime-engine/default-runtime-plugin/.gradle/loom-cache/log4j.xml + log4j2.formatMsgNoLookups=true + fabric.log.disableAnsi=false +clientArgs + --assetIndex + 1.18.2-1.18 + --assetsDir + /home/shedaniel/.gradle/caches/fabric-loom/assets +clientProperties + java.library.path=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/.gradle/loom-cache/natives/1.18.2 + org.lwjgl.librarypath=/home/shedaniel/Documents/JavaCoding/RoughlyEnoughItems-117/.gradle/loom-cache/natives/1.18.2 \ No newline at end of file diff --git a/runtime-engine/default-runtime-plugin/.gradle/loom-cache/log4j.xml b/runtime-engine/default-runtime-plugin/.gradle/loom-cache/log4j.xml new file mode 100644 index 000000000..c009f9fb4 --- /dev/null +++ b/runtime-engine/default-runtime-plugin/.gradle/loom-cache/log4j.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/runtime-engine/default-runtime-plugin/.gradle/loom-cache/remapClasspath.txt b/runtime-engine/default-runtime-plugin/.gradle/loom-cache/remapClasspath.txt new file mode 100644 index 000000000..01f75adc1 --- /dev/null +++ b/runtime-engine/default-runtime-plugin/.gradle/loom-cache/remapClasspath.txt @@ -0,0 +1 @@ +/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/tiny-mappings-parser/0.3.0+build.17/2f10540a290e382a7cd35c16ec3900046a4e252/tiny-mappings-parser-0.3.0+build.17.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.11.2+mixin.0.8.5/f4ae569d559b5e3244b67321945261d83ff7ad8e/sponge-mixin-0.11.2+mixin.0.8.5.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/tiny-remapper/0.8.1/d220c092cd1446d5f2668b53e71abe23a12cb8cf/tiny-remapper-0.8.1.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/access-widener/2.1.0/f62a27adbfd8ab4d4fa5681793039f2c0b177155/access-widener-2.1.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/9.2/81a03f76019c67362299c40e0ba13405f5467bff/asm-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-analysis/9.2/7487dd756daf96cab9986e44b9d7bcb796a61c10/asm-analysis-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-commons/9.2/f4d7f0fc9054386f2893b602454d48e07d4fbead/asm-commons-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-tree/9.2/d96c99a30f5e1a19b0e609dbb19a44d8518ac01e/asm-tree-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-util/9.2/fbc178fc5ba3dab50fd7e8a5317b8b647c8e8946/asm-util-9.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/blocklist/1.0.10/5c685c5ffa94c4cd39496c7184c1d122e515ecef/blocklist-1.0.10.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/patchy/2.2.10/da05971b07cbb379d002cf7eaec6a2048211fefc/patchy-2.2.10.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.ibm.icu/icu4j/70.1/dfa3a1fbc55bf5db8c6e79fc0935ac7ab1202950/icu4j-70.1.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.15/49d94806b6e3dc933dacbd8acb0fdbab8ebd1e5d/commons-codec-1.15.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-compress/1.21/4ec95b60d4e86b5c95a0e919cb172a0af98011ef/commons-compress-1.21.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.13/e5f6cae5ca7ecaac1ec2827a9e2d65ae2869cada/httpclient-4.5.13.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.14/9dd1a631c082d92ecd4bd8fd4cf55026c720a8c1/httpcore-4.4.14.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl/3.2.2/8ad6294407e15780b43e84929c40e4c5e997972e/lwjgl-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-jemalloc/3.2.2/ee8e57a79300f78294576d87c4a587f8c99402e2/lwjgl-jemalloc-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-openal/3.2.2/2b772a102b0a11ee5f2109a5b136f4dc7c630827/lwjgl-openal-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-opengl/3.2.2/6ac5bb88b44c43ea195a570aab059f63da004cd8/lwjgl-opengl-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-glfw/3.2.2/d3ad4df38e400b8afba1de63f84338809399df5b/lwjgl-glfw-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-stb/3.2.2/3b8e6ebc5851dd3d17e37e5cadce2eff2a429f0f/lwjgl-stb-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-tinyfd/3.2.2/fcbe606c8f8da6f8f9a05e2c540eb1ee8632b0e9/lwjgl-tinyfd-3.2.2.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/text2speech/1.12.4/1f618f522dbdd93218c270bcfd8f8dd84be31717/text2speech-1.12.4.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/logging/1.0.0/f6ca3b2eee0b80b384e8ed93d368faecb82dfb9b/logging-1.0.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.github.oshi/oshi-core/5.8.5/1d0ec654d820741327f5a9229d513732a4b7ce50/oshi-core-5.8.5.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/5.10.0/7cf4c87dd802db50721db66947aa237d7ad09418/jna-5.10.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna-platform/5.10.0/fbed7d9669dba47714ad0d4f4454290a997aee69/jna-platform-5.10.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.8.0-beta4/83b0359d847ee053d745be7ec0d8e9e8a44304b4/slf4j-api-1.8.0-beta4.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j18-impl/2.17.0/bd7f6c0b9224dd214afb4e684957e2349b529a8d/log4j-slf4j18-impl-2.17.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/javabridge/1.2.24/c876796229b2ef5120f186eab5acc870699d3b9/javabridge-1.2.24.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.sf.jopt-simple/jopt-simple/5.0.4/4fdac2fbe92dfad86aa6e9301736f6b4342a3f5c/jopt-simple-5.0.4.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/io.netty/netty-all/4.1.68.Final/b8266a3c93c1c051109f71d3449e5dcd5d60b333/netty-all-4.1.68.Final.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.google.guava/failureaccess/1.0.1/1dcf1de382a0bf95a3d8b0849546c88bac1292c9/failureaccess-1.0.1.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/31.0.1-jre/119ea2b2bc205b138974d351777b20f02b92704b/guava-31.0.1-jre.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.12.0/c6842c86792ff03b9f1d1fe2aab8dc23aa6c6f0e/commons-lang3-3.12.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.11.0/a2503f302b11ebde7ebc3df41daebe0e4eea3689/commons-io-2.11.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/brigadier/1.0.18/c1ef1234282716483c92183f49bef47b1a89bfa9/brigadier-1.0.18.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/datafixerupper/4.1.27/a02c43824ce57c3f7a7d7e744f0d99a040398b5/datafixerupper-4.1.27.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.8.9/8a432c1d6825781e21a02db2e2c33c5fde2833b9/gson-2.8.9.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/com.mojang/authlib/3.3.39/289405e70c0917eaeac017f7fba9adb4427baa36/authlib-3.3.39.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/it.unimi.dsi/fastutil/8.5.6/76f95700418a68fbc4ac050525261f05dc681ca1/fastutil-8.5.6.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.17.0/bbd791e9c8c9421e45337c4fe0a10851c086e36c/log4j-api-2.17.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.17.0/fe6e7a32c1228884b9691a744f953a55d0dd8ead/log4j-core-2.17.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/me.shedaniel.cloth/cloth-config/6.2.57/51ec014dad95d65d070f9ef8a715966561998d3b/cloth-config-6.2.57.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/dev.architectury/architectury/4.5.75/aec16eaf48959ed6de2c446609dfa70ed8a8b4dd/architectury-4.5.75.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/me.shedaniel.cloth/basic-math/0.6.0/bcf71444d5a11d1ff0b70ded97c533ece0cea489/basic-math-0.6.0.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/fabric-loader/0.13.3/a91fc6ea7a5e8c3140dfaf34aeadb43ce2f38fe2/fabric-loader-0.13.3.jar:/home/shedaniel/.gradle/caches/modules-2/files-2.1/net.fabricmc/fabric-loader/0.13.3/a91fc6ea7a5e8c3140dfaf34aeadb43ce2f38fe2/fabric-loader-0.13.3.jar:/home/shedaniel/.gradle/caches/fabric-loom/1.18.2/minecraft-merged-intermediary.jar \ No newline at end of file diff --git a/runtime-engine/default-runtime-plugin/build/libs/default-runtime-plugin-transformProductionFabric.jar b/runtime-engine/default-runtime-plugin/build/libs/default-runtime-plugin-transformProductionFabric.jar new file mode 100644 index 000000000..6430324c7 Binary files /dev/null and b/runtime-engine/default-runtime-plugin/build/libs/default-runtime-plugin-transformProductionFabric.jar differ diff --git a/runtime-engine/default-runtime-plugin/build/libs/default-runtime-plugin-transformProductionForge.jar b/runtime-engine/default-runtime-plugin/build/libs/default-runtime-plugin-transformProductionForge.jar new file mode 100644 index 000000000..6430324c7 Binary files /dev/null and b/runtime-engine/default-runtime-plugin/build/libs/default-runtime-plugin-transformProductionForge.jar differ diff --git a/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java new file mode 100644 index 000000000..de9bf4d6e --- /dev/null +++ b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java @@ -0,0 +1,316 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.client.entry; + +import com.google.common.base.Suppliers; +import com.google.common.collect.Lists; +import com.mojang.blaze3d.vertex.PoseStack; +import dev.architectury.fluid.FluidStack; +import dev.architectury.hooks.fluid.FluidStackHooks; +import dev.architectury.platform.Platform; +import dev.architectury.utils.Env; +import dev.architectury.utils.EnvExecutor; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.entry.renderer.AbstractEntryRenderer; +import me.shedaniel.rei.api.client.entry.renderer.BatchedEntryRenderer; +import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; +import me.shedaniel.rei.api.client.util.SpriteRenderer; +import me.shedaniel.rei.api.common.entry.EntrySerializer; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; +import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry; +import me.shedaniel.rei.api.common.entry.type.EntryDefinition; +import me.shedaniel.rei.api.common.entry.type.EntryType; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.ChatFormatting; +import net.minecraft.CrashReport; +import net.minecraft.CrashReportCategory; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.util.Mth; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.material.FlowingFluid; +import net.minecraft.world.level.material.Fluid; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class FluidEntryDefinition implements EntryDefinition, EntrySerializer { + private static final String FLUID_AMOUNT = Platform.isForge() ? "tooltip.rei.fluid_amount.forge" : "tooltip.rei.fluid_amount"; + @Environment(EnvType.CLIENT) + private EntryRenderer renderer; + + public FluidEntryDefinition() { + 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 + public Class getValueType() { + return FluidStack.class; + } + + @Override + public EntryType getType() { + return VanillaEntryTypes.FLUID; + } + + @Override + @Environment(EnvType.CLIENT) + public EntryRenderer getRenderer() { + return renderer; + } + + @Override + @Nullable + public ResourceLocation getIdentifier(EntryStack entry, FluidStack value) { + return Registry.FLUID.getKey(value.getFluid()); + } + + @Override + public boolean isEmpty(EntryStack entry, FluidStack value) { + return value.isEmpty(); + } + + @Override + public FluidStack copy(EntryStack entry, FluidStack value) { + return value.copy(); + } + + @Override + public FluidStack normalize(EntryStack entry, FluidStack value) { + Fluid fluid = value.getFluid(); + if (fluid instanceof FlowingFluid flowingFluid) fluid = flowingFluid.getSource(); + return FluidStack.create(fluid, FluidStack.bucketAmount(), value.getTag()); + } + + @Override + public FluidStack wildcard(EntryStack entry, FluidStack value) { + Fluid fluid = value.getFluid(); + if (fluid instanceof FlowingFluid) fluid = ((FlowingFluid) fluid).getSource(); + return FluidStack.create(fluid, FluidStack.bucketAmount()); + } + + @Override + @Nullable + public ItemStack cheatsAs(EntryStack entry, FluidStack value) { + if (value.isEmpty()) return ItemStack.EMPTY; + Item bucket = value.getFluid().getBucket(); + if (bucket == null) return ItemStack.EMPTY; + return new ItemStack(bucket); + } + + @Nullable + @Override + public FluidStack add(FluidStack o1, FluidStack o2) { + return o1.copyWithAmount(o1.getAmount() + o2.getAmount()); + } + + @Override + public long hash(EntryStack entry, FluidStack value, ComparisonContext context) { + int code = 1; + code = 31 * code + value.getFluid().hashCode(); + code = 31 * code + Long.hashCode(FluidComparatorRegistry.getInstance().hashOf(context, value)); + return code; + } + + @Override + public boolean equals(FluidStack o1, FluidStack o2, ComparisonContext context) { + if (o1.getFluid() != o2.getFluid()) + return false; + return FluidComparatorRegistry.getInstance().hashOf(context, o1) == FluidComparatorRegistry.getInstance().hashOf(context, o2); + } + + @Override + @Nullable + public EntrySerializer getSerializer() { + return this; + } + + @Override + public boolean supportSaving() { + return true; + } + + @Override + public boolean supportReading() { + return true; + } + + @Override + public boolean acceptsNull() { + return false; + } + + @Override + public CompoundTag save(EntryStack entry, FluidStack value) { + return value.write(new CompoundTag()); + } + + @Override + public FluidStack read(CompoundTag tag) { + return FluidStack.read(tag); + } + + @Override + public Component asFormattedText(EntryStack entry, FluidStack value) { + return value.getName(); + } + + @Override + public Stream> getTagsFor(EntryStack entry, FluidStack value) { + return value.getFluid().builtInRegistryHolder().tags(); + } + + @Override + public void fillCrashReport(CrashReport report, CrashReportCategory category, EntryStack entry) { + EntryDefinition.super.fillCrashReport(report, category, entry); + FluidStack stack = entry.getValue(); + category.setDetail("Fluid Type", () -> String.valueOf(Registry.FLUID.getKey(stack.getFluid()))); + category.setDetail("Fluid Amount", () -> String.valueOf(stack.getAmount())); + category.setDetail("Fluid NBT", () -> String.valueOf(stack.getTag())); + } + + @Environment(EnvType.CLIENT) + public static class FluidEntryRenderer extends AbstractEntryRenderer implements BatchedEntryRenderer { + private static final Supplier MISSING_SPRITE = Suppliers.memoize(() -> { + TextureAtlas atlas = Minecraft.getInstance().getModelManager().getAtlas(TextureAtlas.LOCATION_BLOCKS); + return atlas.getSprite(MissingTextureAtlasSprite.getLocation()); + }); + + @Override + public TextureAtlasSprite getExtraData(EntryStack entry) { + FluidStack stack = entry.getValue(); + if (stack.isEmpty()) return null; + return FluidStackHooks.getStillTexture(stack); + } + + private TextureAtlasSprite missingTexture() { + return MISSING_SPRITE.get(); + } + + @Override + public int getBatchIdentifier(EntryStack entry, Rectangle bounds, TextureAtlasSprite extraData) { + return 0; + } + + @Override + public void startBatch(EntryStack entry, TextureAtlasSprite extraData, PoseStack matrices, float delta) {} + + @Override + public void renderBase(EntryStack entry, TextureAtlasSprite sprite, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta) { + TextureAtlasSprite s = sprite == null ? missingTexture() : sprite; + SpriteRenderer.beginPass() + .setup(immediate, RenderType.solid()) + .sprite(s) + .color(sprite == null ? 0xFFFFFF : FluidStackHooks.getColor(entry.getValue())) + .light(0x00f000f0) + .overlay(OverlayTexture.NO_OVERLAY) + .alpha(0xff) + .normal(matrices.last().normal(), 0, 0, 0) + .position(matrices.last().pose(), bounds.x, bounds.getMaxY() - bounds.height * Mth.clamp(entry.get(EntryStack.Settings.FLUID_RENDER_RATIO), 0, 1), bounds.getMaxX(), bounds.getMaxY(), entry.getZ()) + .next(s.atlas().location()); + } + + @Override + public void afterBase(EntryStack entry, TextureAtlasSprite extraData, PoseStack matrices, float delta) {} + + @Override + public void renderOverlay(EntryStack entry, TextureAtlasSprite extraData, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta) {} + + @Override + public void endBatch(EntryStack entry, TextureAtlasSprite extraData, PoseStack matrices, float delta) {} + + @Override + public void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { + FluidStack stack = entry.getValue(); + if (stack.isEmpty()) return; + TextureAtlasSprite sprite = FluidStackHooks.getStillTexture(stack); + if (sprite == null) return; + int color = FluidStackHooks.getColor(stack); + + MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); + + SpriteRenderer.beginPass() + .setup(immediate, RenderType.solid()) + .sprite(sprite) + .color(color) + .light(0x00f000f0) + .overlay(OverlayTexture.NO_OVERLAY) + .alpha(0xff) + .normal(matrices.last().normal(), 0, 0, 0) + .position(matrices.last().pose(), bounds.x, bounds.getMaxY() - bounds.height * Mth.clamp(entry.get(EntryStack.Settings.FLUID_RENDER_RATIO), 0, 1), bounds.getMaxX(), bounds.getMaxY(), entry.getZ()) + .next(InventoryMenu.BLOCK_ATLAS); + + immediate.endBatch(); + } + + @Override + @Nullable + public Tooltip getTooltip(EntryStack entry, TooltipContext context) { + if (entry.isEmpty()) + return null; + List toolTip = Lists.newArrayList(entry.asFormattedText()); + long amount = entry.getValue().getAmount(); + if (amount >= 0 && entry.get(EntryStack.Settings.FLUID_AMOUNT_VISIBLE)) { + String amountTooltip = I18n.get(FLUID_AMOUNT, entry.getValue().getAmount()); + if (amountTooltip != null) { + toolTip.addAll(Stream.of(amountTooltip.split("\n")).map(TextComponent::new).collect(Collectors.toList())); + } + } + if (Minecraft.getInstance().options.advancedItemTooltips) { + ResourceLocation fluidId = Registry.FLUID.getKey(entry.getValue().getFluid()); + toolTip.add((new TextComponent(fluidId.toString())).withStyle(ChatFormatting.DARK_GRAY)); + } + return Tooltip.create(toolTip); + } + } +} diff --git a/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java new file mode 100644 index 000000000..40e61a461 --- /dev/null +++ b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java @@ -0,0 +1,382 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.client.entry; + +import com.google.common.collect.Lists; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.platform.Lighting; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import dev.architectury.hooks.item.ItemStackHooks; +import dev.architectury.utils.Env; +import dev.architectury.utils.EnvExecutor; +import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; +import it.unimi.dsi.fastutil.objects.ReferenceSet; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.entry.renderer.AbstractEntryRenderer; +import me.shedaniel.rei.api.client.entry.renderer.BatchedEntryRenderer; +import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; +import me.shedaniel.rei.api.common.entry.EntrySerializer; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; +import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; +import me.shedaniel.rei.api.common.entry.type.EntryDefinition; +import me.shedaniel.rei.api.common.entry.type.EntryType; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; +import me.shedaniel.rei.api.common.util.ImmutableTextComponent; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.CrashReport; +import net.minecraft.CrashReportCategory; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; + +public class ItemEntryDefinition implements EntryDefinition, EntrySerializer { + @Environment(EnvType.CLIENT) + private EntryRenderer renderer; + + public ItemEntryDefinition() { + 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 + public Class getValueType() { + return ItemStack.class; + } + + @Override + public EntryType getType() { + return VanillaEntryTypes.ITEM; + } + + @Override + @Environment(EnvType.CLIENT) + public EntryRenderer getRenderer() { + return renderer; + } + + @Override + @Nullable + public ResourceLocation getIdentifier(EntryStack entry, ItemStack value) { + return Registry.ITEM.getKey(value.getItem()); + } + + @Override + public boolean isEmpty(EntryStack entry, ItemStack value) { + return value.isEmpty(); + } + + @Override + public ItemStack copy(EntryStack entry, ItemStack value) { + return value.copy(); + } + + @Override + public ItemStack normalize(EntryStack entry, ItemStack value) { + ItemStack copy = value.copy(); + copy.setCount(1); + return copy; + } + + @Override + public ItemStack wildcard(EntryStack entry, ItemStack value) { + return new ItemStack(value.getItem(), 1); + } + + @Override + @Nullable + public ItemStack cheatsAs(EntryStack entry, ItemStack value) { + return value.copy(); + } + + @Nullable + @Override + public ItemStack add(ItemStack o1, ItemStack o2) { + return ItemStackHooks.copyWithCount(o1, o1.getCount() + o2.getCount()); + } + + @Override + public long hash(EntryStack entry, ItemStack value, ComparisonContext context) { + int code = 1; + code = 31 * code + System.identityHashCode(value.getItem()); + code = 31 * code + Long.hashCode(ItemComparatorRegistry.getInstance().hashOf(context, value)); + return code; + } + + @Override + public boolean equals(ItemStack o1, ItemStack o2, ComparisonContext context) { + if (o1.getItem() != o2.getItem()) + return false; + return ItemComparatorRegistry.getInstance().hashOf(context, o1) == ItemComparatorRegistry.getInstance().hashOf(context, o2); + } + + @Override + @Nullable + public EntrySerializer getSerializer() { + return this; + } + + @Override + public boolean supportSaving() { + return true; + } + + @Override + public boolean supportReading() { + return true; + } + + @Override + public boolean acceptsNull() { + return false; + } + + @Override + public CompoundTag save(EntryStack entry, ItemStack value) { + return value.save(new CompoundTag()); + } + + @Override + public ItemStack read(CompoundTag tag) { + return ItemStack.of(tag); + } + + private static final ReferenceSet SEARCH_BLACKLISTED = new ReferenceOpenHashSet<>(); + + @Override + public Component asFormattedText(EntryStack entry, ItemStack value) { + return asFormattedText(entry, value, TooltipContext.of()); + } + + @Override + public Component asFormattedText(EntryStack entry, ItemStack value, TooltipContext context) { + if (!SEARCH_BLACKLISTED.contains(value.getItem())) + try { + return value.getHoverName(); + } catch (Throwable e) { + if (context != null && context.isSearch()) throw e; + e.printStackTrace(); + SEARCH_BLACKLISTED.add(value.getItem()); + } + try { + return new ImmutableTextComponent(I18n.get("item." + Registry.ITEM.getKey(value.getItem()).toString().replace(":", "."))); + } catch (Throwable e) { + e.printStackTrace(); + } + return new ImmutableTextComponent("ERROR"); + } + + @Override + public Stream> getTagsFor(EntryStack entry, ItemStack value) { + return value.getTags(); + } + + @Environment(EnvType.CLIENT) + private List tryGetItemStackToolTip(EntryStack entry, ItemStack value, TooltipContext context) { + if (!SEARCH_BLACKLISTED.contains(value.getItem())) + try { + return value.getTooltipLines(Minecraft.getInstance().player, context.getFlag()); + } catch (Throwable e) { + if (context.isSearch()) throw e; + e.printStackTrace(); + SEARCH_BLACKLISTED.add(value.getItem()); + } + return Lists.newArrayList(asFormattedText(entry, value, context)); + } + + @Override + public void fillCrashReport(CrashReport report, CrashReportCategory category, EntryStack entry) { + EntryDefinition.super.fillCrashReport(report, category, entry); + ItemStack stack = entry.getValue(); + category.setDetail("Item Type", () -> String.valueOf(stack.getItem())); + category.setDetail("Item Damage", () -> String.valueOf(stack.getDamageValue())); + category.setDetail("Item NBT", () -> String.valueOf(stack.getTag())); + category.setDetail("Item Foil", () -> String.valueOf(stack.hasFoil())); + } + + @Environment(EnvType.CLIENT) + public class ItemEntryRenderer extends AbstractEntryRenderer implements BatchedEntryRenderer { + private static final float SCALE = 20.0F; + public static final int ITEM_LIGHT = 0xf000f0; + + @Override + public BakedModel getExtraData(EntryStack entry) { + return Minecraft.getInstance().getItemRenderer().getModel(entry.getValue(), null, null, 0); + } + + @Override + public void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { + BakedModel model = getExtraData(entry); + setupGL(entry, model); + if (!entry.isEmpty()) { + ItemStack value = entry.getValue(); + matrices.pushPose(); + matrices.mulPoseMatrix(RenderSystem.getModelViewMatrix()); + matrices.translate(bounds.getCenterX(), bounds.getCenterY(), entry.getZ()); + matrices.scale(bounds.getWidth(), (bounds.getWidth() + bounds.getHeight()) / -2f, 1.0F); + PoseStack modelViewStack = RenderSystem.getModelViewStack(); + modelViewStack.pushPose(); + modelViewStack.last().pose().load(matrices.last().pose()); + RenderSystem.applyModelViewMatrix(); + MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource(); + Minecraft.getInstance().getItemRenderer().render(value, ItemTransforms.TransformType.GUI, false, new PoseStack(), immediate, + ITEM_LIGHT, OverlayTexture.NO_OVERLAY, model); + immediate.endBatch(); + matrices.popPose(); + modelViewStack.popPose(); + RenderSystem.applyModelViewMatrix(); + } + PoseStack modelViewStack = RenderSystem.getModelViewStack(); + modelViewStack.pushPose(); + modelViewStack.mulPoseMatrix(matrices.last().pose()); + modelViewStack.translate(bounds.x, bounds.y, 0); + modelViewStack.scale(bounds.width / 16f, (bounds.getWidth() + bounds.getHeight()) / 2f / 16f, 1.0F); + RenderSystem.applyModelViewMatrix(); + renderOverlay(entry, bounds); + modelViewStack.popPose(); + endGL(entry, model); + RenderSystem.applyModelViewMatrix(); + } + + @Override + public int getBatchIdentifier(EntryStack entry, Rectangle bounds, BakedModel model) { + return 1738923 + (model.usesBlockLight() ? 1 : 0); + } + + @Override + public void startBatch(EntryStack entry, BakedModel model, PoseStack matrices, float delta) { + setupGL(entry, model); + PoseStack modelViewStack = RenderSystem.getModelViewStack(); + modelViewStack.pushPose(); + modelViewStack.scale(SCALE, -SCALE, 1.0F); + RenderSystem.applyModelViewMatrix(); + } + + public void setupGL(EntryStack entry, BakedModel model) { + Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS).setFilter(false, false); + RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS); + RenderSystem.enableBlend(); + RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + boolean sideLit = model.usesBlockLight(); + if (!sideLit) Lighting.setupForFlatItems(); + } + + @Override + public void renderBase(EntryStack entry, BakedModel model, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta) { + if (!entry.isEmpty()) { + ItemStack value = entry.getValue(); + matrices.pushPose(); + matrices.translate(bounds.getCenterX() / SCALE, bounds.getCenterY() / -SCALE, entry.getZ()); + matrices.scale(bounds.getWidth() / SCALE, (bounds.getWidth() + bounds.getHeight()) / 2f / SCALE, 1.0F); + Minecraft.getInstance().getItemRenderer().render(value, ItemTransforms.TransformType.GUI, false, matrices, immediate, + ITEM_LIGHT, OverlayTexture.NO_OVERLAY, model); + matrices.popPose(); + } + } + + @Override + public void afterBase(EntryStack entry, BakedModel model, PoseStack matrices, float delta) { + endGL(entry, model); + RenderSystem.getModelViewStack().popPose(); + RenderSystem.applyModelViewMatrix(); + } + + @Override + public void renderOverlay(EntryStack entry, BakedModel model, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta) { + PoseStack modelViewStack = RenderSystem.getModelViewStack(); + modelViewStack.pushPose(); + modelViewStack.mulPoseMatrix(matrices.last().pose()); + modelViewStack.translate(bounds.x, bounds.y, 0); + modelViewStack.scale(bounds.width / 16f, (bounds.getWidth() + bounds.getHeight()) / 2f / 16f, 1.0F); + RenderSystem.applyModelViewMatrix(); + renderOverlay(entry, bounds); + modelViewStack.popPose(); + RenderSystem.applyModelViewMatrix(); + } + + public void renderOverlay(EntryStack entry, Rectangle bounds) { + if (!entry.isEmpty()) { + Minecraft.getInstance().getItemRenderer().blitOffset = entry.getZ(); + Minecraft.getInstance().getItemRenderer().renderGuiItemDecorations(Minecraft.getInstance().font, entry.getValue(), 0, 0, null); + Minecraft.getInstance().getItemRenderer().blitOffset = 0.0F; + } + } + + @Override + public void endBatch(EntryStack entry, BakedModel model, PoseStack matrices, float delta) { + } + + public void endGL(EntryStack entry, BakedModel model) { + RenderSystem.enableDepthTest(); + boolean sideLit = model.usesBlockLight(); + if (!sideLit) Lighting.setupFor3DItems(); + } + + @Override + @Nullable + public Tooltip getTooltip(EntryStack entry, TooltipContext context) { + if (entry.isEmpty()) + return null; + Tooltip tooltip = Tooltip.create(); + Optional component = entry.getValue().getTooltipImage(); + List components = tryGetItemStackToolTip(entry, entry.getValue(), context); + if (!components.isEmpty()) { + tooltip.add(components.get(0)); + } + component.ifPresent(tooltip::add); + for (int i = 1; i < components.size(); i++) { + tooltip.add(components.get(i)); + } + return tooltip; + } + } +} diff --git a/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java new file mode 100644 index 000000000..533af546a --- /dev/null +++ b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java @@ -0,0 +1,56 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.runtime; + +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.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Optional; +import java.util.stream.Stream; + +@ApiStatus.Internal +public class DefaultRuntimePlugin implements REIServerPlugin { + @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 = FluidSupportProvider.getInstance().itemToFluids(input); + if (!stream.isPresent()) { + return CompoundEventResult.pass(); + } + return CompoundEventResult.interruptTrue(stream.get()); + }); + } +} diff --git a/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java new file mode 100644 index 000000000..7eed62ba2 --- /dev/null +++ b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java @@ -0,0 +1,105 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.test; + +import com.google.common.collect.ImmutableList; +import me.shedaniel.rei.api.client.favorites.FavoriteEntry; +import me.shedaniel.rei.api.client.favorites.FavoriteEntryType; +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; +import me.shedaniel.rei.api.common.plugins.PluginManager; +import me.shedaniel.rei.api.common.registry.ReloadStage; +import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.impl.common.InternalLogger; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.GameType; +import org.jetbrains.annotations.TestOnly; + +import java.util.Random; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +@TestOnly +@Environment(EnvType.CLIENT) +public class REITestPlugin implements REIClientPlugin { + private Random random = new Random(); + + @Override + public void preStage(PluginManager manager, ReloadStage stage) { + InternalLogger.getInstance().error("REI Test Plugin is enabled! If you see this unintentionally, please report this!"); + } + + @Override + public void registerEntries(EntryRegistry registry) { + int times = 100; + for (Item item : Registry.ITEM) { + EntryStack base = EntryStacks.of(item); + registry.addEntriesAfter(base, IntStream.range(0, times).mapToObj(value -> transformStack(EntryStacks.of(item))).collect(Collectors.toList())); + try { + for (ItemStack stack : registry.appendStacksForItem(item)) { + registry.addEntries(IntStream.range(0, times).mapToObj(value -> transformStack(EntryStacks.of(stack))).collect(Collectors.toList())); + } + } catch (Exception ignored) { + } + } + } + + @Override + public void registerItemComparators(ItemComparatorRegistry registry) { + registry.registerNbt(Registry.ITEM.stream().toArray(Item[]::new)); + } + + public EntryStack transformStack(EntryStack stack) { + CompoundTag tag = stack.getValue().getOrCreateTag(); + tag.putInt("Whatever", random.nextInt(Integer.MAX_VALUE)); + return stack; + } + + @Override + public void registerFavorites(FavoriteEntryType.Registry registry) { + registry.registerSystemFavorites(() -> { + GameType mode = Minecraft.getInstance().gameMode.getPlayerMode(); + switch (mode) { + case SURVIVAL: + return ImmutableList.of(FavoriteEntry.fromEntryStack(EntryStacks.of(Items.STONE))); + case CREATIVE: + return ImmutableList.of(FavoriteEntry.fromEntryStack(EntryStacks.of(Items.PACKED_ICE))); + case ADVENTURE: + return ImmutableList.of(FavoriteEntry.fromEntryStack(EntryStacks.of(Items.ANVIL))); + case SPECTATOR: + default: + return ImmutableList.of(); + } + }); + } +} -- cgit