aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/plugin/client
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2024-10-26 16:55:52 +0800
committershedaniel <daniel@shedaniel.me>2024-10-26 16:55:57 +0800
commitddb48e2032d1986709cad973067693eec3118504 (patch)
treee7905130008c67767d2ad2a4d72f49ba4df7e6e3 /runtime/src/main/java/me/shedaniel/rei/plugin/client
parenteaf9236e3da2adafcea204778ecc0072e70d0aa5 (diff)
downloadRoughlyEnoughItems-ddb48e2032d1986709cad973067693eec3118504.tar.gz
RoughlyEnoughItems-ddb48e2032d1986709cad973067693eec3118504.tar.bz2
RoughlyEnoughItems-ddb48e2032d1986709cad973067693eec3118504.zip
Update to 1.21.2 (Please read Primer)
https://hackmd.io/@shedaniel/rei17_primer
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/plugin/client')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java22
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java41
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java37
3 files changed, 43 insertions, 57 deletions
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 93aac1fa6..ae94f80dc 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
@@ -25,6 +25,7 @@ package me.shedaniel.rei.plugin.client.entry;
import com.google.common.base.Suppliers;
import com.google.common.collect.Lists;
+import com.mojang.serialization.Codec;
import dev.architectury.fluid.FluidStack;
import dev.architectury.hooks.fluid.FluidStackHooks;
import dev.architectury.platform.Platform;
@@ -60,10 +61,11 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.registries.BuiltInRegistries;
-import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
+import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
+import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.util.Mth;
@@ -178,28 +180,18 @@ public class FluidEntryDefinition implements EntryDefinition<FluidStack>, EntryS
}
@Override
- public boolean supportSaving() {
- return true;
- }
-
- @Override
- public boolean supportReading() {
- return true;
- }
-
- @Override
public boolean acceptsNull() {
return false;
}
@Override
- public CompoundTag save(EntryStack<FluidStack> entry, FluidStack value) {
- return (CompoundTag) value.write(BasicDisplay.registryAccess(), new CompoundTag());
+ public Codec<FluidStack> codec() {
+ return FluidStack.CODEC;
}
@Override
- public FluidStack read(CompoundTag tag) {
- return FluidStack.read(BasicDisplay.registryAccess(), tag).orElse(FluidStack.empty());
+ public StreamCodec<RegistryFriendlyByteBuf, FluidStack> streamCodec() {
+ return FluidStack.STREAM_CODEC;
}
@Override
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 2d5595ad6..6200ce8cd 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
@@ -27,6 +27,7 @@ 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.serialization.Codec;
import dev.architectury.hooks.item.ItemStackHooks;
import dev.architectury.utils.Env;
import dev.architectury.utils.EnvExecutor;
@@ -57,11 +58,13 @@ 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.component.DataComponentPatch;
+import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
-import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
+import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
+import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
@@ -170,28 +173,18 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer
}
@Override
- public boolean supportSaving() {
- return true;
- }
-
- @Override
- public boolean supportReading() {
- return true;
- }
-
- @Override
public boolean acceptsNull() {
return false;
}
@Override
- public CompoundTag save(EntryStack<ItemStack> entry, ItemStack value) {
- return (CompoundTag) value.save(BasicDisplay.registryAccess());
+ public Codec<ItemStack> codec() {
+ return ItemStack.CODEC;
}
@Override
- public ItemStack read(CompoundTag tag) {
- return ItemStack.parseOptional(BasicDisplay.registryAccess(), tag);
+ public StreamCodec<RegistryFriendlyByteBuf, ItemStack> streamCodec() {
+ return ItemStack.OPTIONAL_STREAM_CODEC;
}
private static final ReferenceSet<Item> SEARCH_BLACKLISTED = new ReferenceOpenHashSet<>();
@@ -283,11 +276,13 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer
modelViewStack.mul(graphics.pose().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(new GuiGraphics(Minecraft.getInstance(), graphics.bufferSource()), entry, bounds);
+ graphics.drawSpecial(source -> {
+ if (source instanceof MultiBufferSource.BufferSource multiBufferSource) {
+ renderOverlay(new GuiGraphics(Minecraft.getInstance(), multiBufferSource), entry, bounds);
+ }
+ });
modelViewStack.popMatrix();
endGL(entry, model);
- RenderSystem.applyModelViewMatrix();
}
@Override
@@ -335,10 +330,12 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer
modelViewStack.mul(graphics.pose().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(new GuiGraphics(Minecraft.getInstance(), graphics.bufferSource()), entry, bounds);
+ graphics.drawSpecial(source -> {
+ if (source instanceof MultiBufferSource.BufferSource multiBufferSource) {
+ renderOverlay(new GuiGraphics(Minecraft.getInstance(), multiBufferSource), entry, bounds);
+ }
+ });
modelViewStack.popMatrix();
- RenderSystem.applyModelViewMatrix();
}
public void renderOverlay(GuiGraphics graphics, EntryStack<ItemStack> entry, Rectangle bounds) {
@@ -372,7 +369,7 @@ public class ItemEntryDefinition implements EntryDefinition<ItemStack>, EntrySer
for (int i = 1; i < components.size(); i++) {
tooltip.add(components.get(i));
}
- return tooltip;
+ return tooltip.withTooltipStyle(entry.getValue().get(DataComponents.TOOLTIP_STYLE));
}
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
index 4108837f9..fa300a5ba 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
@@ -34,12 +34,12 @@ import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
import me.shedaniel.rei.api.client.favorites.FavoriteEntryType;
import me.shedaniel.rei.api.client.gui.Renderer;
-import me.shedaniel.rei.api.client.gui.config.RecipeBorderType;
import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponent;
import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentProviderWidget;
import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentVisitorWidget;
import me.shedaniel.rei.api.client.gui.screen.DisplayScreen;
import me.shedaniel.rei.api.client.gui.widgets.*;
+import me.shedaniel.rei.api.client.gui.widgets.utils.PanelTextures;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
@@ -47,12 +47,11 @@ import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.client.registry.screen.ExclusionZones;
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
-import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry;
import me.shedaniel.rei.api.client.search.method.InputMethodRegistry;
import me.shedaniel.rei.api.client.util.ClientEntryStacks;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
-import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry;
+import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.plugins.PluginManager;
@@ -74,14 +73,16 @@ import me.shedaniel.rei.impl.common.InternalLogger;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryListener;
import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper;
-import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.client.renderer.RenderType;
import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.NbtOps;
+import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;
@@ -117,7 +118,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
@Override
public void render(GuiGraphics graphics, Rectangle bounds, int mouseX, int mouseY, float delta) {
- graphics.innerBlit(id, bounds.x, bounds.getMaxX(), bounds.y, bounds.getMaxY(), 0, 0, 1, 0, 1);
+ graphics.innerBlit(RenderType::guiTextured, id, bounds.x, bounds.getMaxX(), bounds.y, bounds.getMaxY(), 0, 0, 1, 0, 1);
}
@Override
@@ -177,11 +178,6 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
}
@Override
- public void registerTransferHandlers(TransferHandlerRegistry registry) {
- registry.register(new DefaultCategoryHandler());
- }
-
- @Override
public void registerInputMethods(InputMethodRegistry registry) {
registry.add(DefaultInputMethod.ID, DefaultInputMethod.INSTANCE);
UniHanManager manager = new UniHanManager(Platform.getConfigFolder().resolve("roughlyenoughitems/unihan.zip"));
@@ -203,13 +199,13 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
@Override
public DataResult<EntryStackFavoriteEntry> read(CompoundTag object) {
- EntryStack<?> stack;
try {
- stack = EntryStack.read(object.getCompound(key));
+ return EntryStack.codec().parse(BasicDisplay.registryAccess().createSerializationContext(NbtOps.INSTANCE), object.getCompound(key))
+ .map(EntryStackFavoriteEntry::new)
+ .setLifecycle(Lifecycle.stable());
} catch (Throwable throwable) {
return DataResult.error(throwable::getMessage);
}
- return DataResult.success(new EntryStackFavoriteEntry(stack), Lifecycle.stable());
}
@Override
@@ -217,14 +213,14 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
if (args.length == 0) return DataResult.error(() -> "Cannot create EntryStackFavoriteEntry from empty args!");
if (!(args[0] instanceof EntryStack<?> stack))
return DataResult.error(() -> "Creation of EntryStackFavoriteEntry from args expected EntryStack as the first argument!");
- if (!stack.supportSaving())
+ if (!stack.supportSerialization())
return DataResult.error(() -> "Creation of EntryStackFavoriteEntry from an unserializable stack!");
return DataResult.success(new EntryStackFavoriteEntry(stack), Lifecycle.stable());
}
@Override
public CompoundTag save(EntryStackFavoriteEntry entry, CompoundTag tag) {
- tag.put(key, entry.stack.saveStack());
+ tag.put(key, EntryStack.codec().encodeStart(BasicDisplay.registryAccess().createSerializationContext(NbtOps.INSTANCE), entry.stack).getOrThrow());
return tag;
}
}
@@ -290,8 +286,8 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
public DataResult<DisplayFavoriteEntry> read(CompoundTag object) {
try {
if (object.contains("Data")) {
- Display display = DisplaySerializerRegistry.getInstance().read(CategoryIdentifier.of(object.getString("CategoryID")), object.getCompound("Data"));
- return DataResult.success(new DisplayFavoriteEntry(display, UUID.fromString(object.getString("UUID"))), Lifecycle.stable());
+ DataResult<Display> result = Display.codec().parse(BasicDisplay.registryAccess().createSerializationContext(NbtOps.INSTANCE), object.getCompound("Data"));
+ return DataResult.success(new DisplayFavoriteEntry(result.getOrThrow(), UUID.fromString(object.getString("UUID"))), Lifecycle.stable());
} else {
return DataResult.success(new DisplayFavoriteEntry(null, UUID.fromString(object.getString("UUID"))), Lifecycle.stable());
}
@@ -310,13 +306,14 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
@Override
public CompoundTag save(DisplayFavoriteEntry entry, CompoundTag tag) {
- boolean hasSerializer = DisplaySerializerRegistry.getInstance().hasSerializer(entry.display.getCategoryIdentifier());
+ boolean hasSerializer = entry.display.getSerializer() != null;
tag.putString("CategoryID", entry.display.getCategoryIdentifier().toString());
tag.putString("UUID", entry.uuid.toString());
if (hasSerializer) {
try {
- tag.put("Data", DisplaySerializerRegistry.getInstance().save(entry.display, new CompoundTag()));
+ DataResult<Tag> displayTag = Display.codec().encodeStart(BasicDisplay.registryAccess().createSerializationContext(NbtOps.INSTANCE), entry.display);
+ tag.put("Data", displayTag.getOrThrow());
} catch (Exception e) {
InternalLogger.getInstance().warn("Failed to save display favorite entry", e);
}
@@ -353,7 +350,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
@Override
public Renderer getRenderer(boolean showcase) {
Panel panel = Widgets.createRecipeBase(new Rectangle(0, 0, 18, 18))
- .yTextureOffset(RecipeBorderType.LIGHTER.getYOffset());
+ .texture(PanelTextures.LIGHTER);
Slot slot = Widgets.createSlot(new Rectangle())
.disableBackground()
.disableHighlight()