From c0c2bd8d259b9ccc55d2111d806220753b9d89bd Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 27 Jun 2021 16:38:33 +0800 Subject: Fix #572 & add getDraggableAcceptingBounds --- .../shedaniel/rei/plugin/client/DefaultClientPlugin.java | 4 ++-- .../plugin/client/favorites/GameModeFavoriteEntry.java | 13 +++++++++---- .../rei/plugin/client/favorites/WeatherFavoriteEntry.java | 15 ++++++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) (limited to 'default-plugin/src/main/java/me') diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java index cfbfa0da2..ae38726c3 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java @@ -343,13 +343,13 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin Arrays.stream(GameType.values()) .filter(type -> type.getId() >= 0), Stream.of((GameType) null) - ).map(GameModeFavoriteEntry.Type.INSTANCE::fromArgs).toArray(FavoriteEntry[]::new)); + ).map(GameModeFavoriteEntry::new).toArray(FavoriteEntry[]::new)); registry.register(WeatherFavoriteEntry.ID, WeatherFavoriteEntry.Type.INSTANCE); registry.getOrCrateSection(new TranslatableComponent(WeatherFavoriteEntry.TRANSLATION_KEY)) .add(Stream.concat( Arrays.stream(WeatherFavoriteEntry.Weather.values()), Stream.of((WeatherFavoriteEntry.Weather) null) - ).map(WeatherFavoriteEntry.Type.INSTANCE::fromArgs).toArray(FavoriteEntry[]::new)); + ).map(WeatherFavoriteEntry::new).toArray(FavoriteEntry[]::new)); } @Override diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java index c50590376..47d023529 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java @@ -24,6 +24,8 @@ package me.shedaniel.rei.plugin.client.favorites; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.Lifecycle; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; @@ -188,15 +190,18 @@ public class GameModeFavoriteEntry extends FavoriteEntry { INSTANCE; @Override - public GameModeFavoriteEntry read(CompoundTag object) { + public DataResult readResult(CompoundTag object) { String stringValue = object.getString(KEY); GameType type = stringValue.equals("NOT_SET") ? null : GameType.valueOf(stringValue); - return new GameModeFavoriteEntry(type); + return DataResult.success(new GameModeFavoriteEntry(type), Lifecycle.stable()); } @Override - public GameModeFavoriteEntry fromArgs(Object... args) { - return new GameModeFavoriteEntry((GameType) args[0]); + public DataResult fromArgsResult(Object... args) { + if (args.length == 0) return DataResult.error("Cannot create GameModeFavoriteEntry from empty args!"); + if (!(args[0] instanceof GameType type)) + return DataResult.error("Creation of GameModeFavoriteEntry from args expected GameType as the first argument!"); + return DataResult.success(new GameModeFavoriteEntry(type), Lifecycle.stable()); } @Override diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java index 08786e341..55483ac53 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java @@ -25,6 +25,8 @@ package me.shedaniel.rei.plugin.client.favorites; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.Lifecycle; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; @@ -195,15 +197,18 @@ public class WeatherFavoriteEntry extends FavoriteEntry { INSTANCE; @Override - public WeatherFavoriteEntry read(CompoundTag object) { + public DataResult readResult(CompoundTag object) { String stringValue = object.getString(KEY); - Weather type = stringValue.equals("NOT_SET") ? null : Weather.valueOf(stringValue); - return new WeatherFavoriteEntry(type); + Weather weather = stringValue.equals("NOT_SET") ? null : Weather.valueOf(stringValue); + return DataResult.success(new WeatherFavoriteEntry(weather), Lifecycle.stable()); } @Override - public WeatherFavoriteEntry fromArgs(Object... args) { - return new WeatherFavoriteEntry((Weather) args[0]); + public DataResult fromArgsResult(Object... args) { + if (args.length == 0) return DataResult.error("Cannot create WeatherFavoriteEntry from empty args!"); + if (!(args[0] instanceof Weather weather)) + return DataResult.error("Creation of WeatherFavoriteEntry from args expected Weather as the first argument!"); + return DataResult.success(new WeatherFavoriteEntry(weather), Lifecycle.stable()); } @Override -- cgit