aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-10-22 01:11:04 +0800
committershedaniel <daniel@shedaniel.me>2022-10-22 01:12:32 +0800
commit0ef0f8b21df4b9a603aaa2ab4a35d395ef6437c1 (patch)
treef6f38140f94fa98adcad5b880fdc2aa3bd4df844
parentbb7920e447d599d23abfac3b67d8823cf24f8150 (diff)
downloadRoughlyEnoughItems-0ef0f8b21df4b9a603aaa2ab4a35d395ef6437c1.tar.gz
RoughlyEnoughItems-0ef0f8b21df4b9a603aaa2ab4a35d395ef6437c1.tar.bz2
RoughlyEnoughItems-0ef0f8b21df4b9a603aaa2ab4a35d395ef6437c1.zip
Make it not crash
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java4
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModule.java54
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModuleKey.java (renamed from shared-internals/src/main/java/me/shedaniel/rei/impl/common/networking/NetworkModule.java)20
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java39
-rwxr-xr-xbuild.gradle1
-rw-r--r--default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java6
-rw-r--r--runtime-engine/initialization/src/main/java/me/shedaniel/rei/impl/common/init/CoreInitialization.java2
-rw-r--r--runtime-engine/menu-info/src/main/java/me/shedaniel/rei/impl/common/transfer/TransferNetworkModule.java (renamed from runtime-engine/menu-info/src/main/java/me/shedaniel/rei/impl/common/transfer/REITransferNetwork.java)27
-rw-r--r--runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java19
-rw-r--r--runtime-engine/menu-info/src/main/resources/META-INF/services/me.shedaniel.rei.api.common.networking.NetworkModule1
-rw-r--r--runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/client/networking/modules/CheatItemStatusNetworkModule.java78
-rw-r--r--runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/client/networking/modules/NotEnoughItemsNetworkModule.java111
-rw-r--r--runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/common/networking/NetworkingHelperImpl.java89
-rw-r--r--runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/common/networking/modules/CheatItemGiveNetworkModule.java78
-rw-r--r--runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/common/networking/modules/CheatItemGrabNetworkModule.java86
-rw-r--r--runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/common/networking/modules/CheatItemHotbarNetworkModule.java85
-rw-r--r--runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/common/networking/modules/DeleteItemNetworkModule.java76
-rw-r--r--runtime-engine/networking/src/main/resources/META-INF/services/me.shedaniel.rei.api.common.networking.NetworkModule6
-rw-r--r--runtime-engine/networking/src/main/resources/META-INF/services/me.shedaniel.rei.api.common.networking.NetworkingHelper1
-rw-r--r--runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/EntryListWidgetImpl.java5
-rw-r--r--runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/entries/paginated/PaginatedEntryListWidget.java2
-rw-r--r--runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/ConfigButtonWidgetProvider.java14
-rw-r--r--runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/CraftableFilterButtonWidgetProvider.java11
-rw-r--r--runtime-frontend/overlay-entries/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/SearchFieldWidgetProvider.java9
-rw-r--r--runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayImpl.java34
-rw-r--r--runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/widgets/OverlayWidgetProvider.java11
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java1
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java49
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java124
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/ClientNetworkHelperImpl.java59
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java6
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/toast/CopyRecipeIdentifierToast.java6
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/toast/ExportRecipeIdentifierToast.java10
-rwxr-xr-xsettings.gradle1
-rw-r--r--shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/InternalTextures.java1
35 files changed, 801 insertions, 325 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java b/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java
index c044b583c..5eb95053b 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java
@@ -28,6 +28,7 @@ import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.api.client.view.ViewSearchBuilder;
import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.networking.NetworkModule;
import me.shedaniel.rei.api.common.networking.NetworkingHelper;
import me.shedaniel.rei.api.common.util.FormattingUtils;
import me.shedaniel.rei.impl.client.ClientInternals;
@@ -207,7 +208,8 @@ public interface ClientHelper {
*
* @return whether the client can use move items packets
*/
+ @Deprecated(forRemoval = true)
default boolean canUseMovePackets() {
- return NetworkingHelper.getInstance().client().canUseMovePackets();
+ return NetworkingHelper.getInstance().canUse(NetworkModule.TRANSFER);
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModule.java b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModule.java
new file mode 100644
index 000000000..fd8e644d1
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModule.java
@@ -0,0 +1,54 @@
+/*
+ * 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.api.common.networking;
+
+import me.shedaniel.rei.api.common.category.CategoryIdentifier;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.util.Unit;
+import net.minecraft.world.item.ItemStack;
+import org.jetbrains.annotations.ApiStatus;
+
+import java.util.List;
+import java.util.Map;
+
+@ApiStatus.Experimental
+public interface NetworkModule<T> {
+ NetworkModuleKey<Unit> DELETE_ITEM = new NetworkModuleKey<>() {};
+ NetworkModuleKey<ItemStack> CHEAT_GIVE = new NetworkModuleKey<>() {};
+ NetworkModuleKey<Map.Entry<ItemStack, Integer>> CHEAT_HOTBAR = new NetworkModuleKey<>() {};
+ NetworkModuleKey<ItemStack> CHEAT_GRAB = new NetworkModuleKey<>() {};
+ NetworkModuleKey<Map.Entry<ItemStack, String>> CHEAT_STATUS_REPLY = new NetworkModuleKey<>() {};
+ NetworkModuleKey<List<List<ItemStack>>> NOT_ENOUGH_ITEMS = new NetworkModuleKey<>() {};
+ NetworkModuleKey<TransferData> TRANSFER = new NetworkModuleKey<>() {};
+
+ NetworkModuleKey<T> getKey();
+
+ boolean canUse(Object target);
+
+ void onInitialize();
+
+ void send(Object target, T data);
+
+ record TransferData(CategoryIdentifier<?> categoryIdentifier, boolean stacked, CompoundTag displayTag) {}
+}
diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/common/networking/NetworkModule.java b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModuleKey.java
index 72ab29c8c..155aff65a 100644
--- a/shared-internals/src/main/java/me/shedaniel/rei/impl/common/networking/NetworkModule.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModuleKey.java
@@ -21,23 +21,7 @@
* SOFTWARE.
*/
-package me.shedaniel.rei.impl.common.networking;
+package me.shedaniel.rei.api.common.networking;
-import org.jetbrains.annotations.ApiStatus;
-
-@ApiStatus.Internal
-public interface NetworkModule {
- Object DELETE = new Object();
- Object CREATE = new Object();
- Object CREATE_HOTBAR = new Object();
- Object CREATE_GRAB = new Object();
- Object CREATE_MSG = new Object();
- Object NOT_ENOUGH_ITEMS = new Object();
- Object TRANSFER = new Object();
-
- Object getKey();
-
- boolean canUse();
-
- void onInitialize();
+public interface NetworkModuleKey<T> {
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java
index ca1e2ad41..5c1b7e9b9 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java
@@ -26,31 +26,38 @@ package me.shedaniel.rei.api.common.networking;
import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.api.common.plugins.REIServerPlugin;
import me.shedaniel.rei.api.common.registry.Reloadable;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+import net.minecraft.server.level.ServerPlayer;
+
+import java.util.Objects;
public interface NetworkingHelper extends Reloadable<REIServerPlugin> {
static NetworkingHelper getInstance() {
return PluginManager.getServerInstance().get(NetworkingHelper.class);
}
+ <T> boolean has(NetworkModuleKey<T> moduleKey);
+
+ <T> boolean canUse(NetworkModuleKey<T> moduleKey);
+
+ <T> boolean canPlayerUse(ServerPlayer player, NetworkModuleKey<T> moduleKey);
+
+ <T> void send(Object target, NetworkModuleKey<T> moduleKey, T data);
+
+ default <T> void sendToServer(NetworkModuleKey<T> moduleKey, T data) {
+ send(null, moduleKey, data);
+ }
+
+ default <T> void sendToPlayer(ServerPlayer player, NetworkModuleKey<T> moduleKey, T data) {
+ send(Objects.requireNonNull(player, "player"), moduleKey, data);
+ }
+
+ @Environment(EnvType.CLIENT)
Client client();
+ @Environment(EnvType.CLIENT)
interface Client {
- boolean hasPermissionToUsePackets();
-
boolean hasOperatorPermission();
-
- /**
- * Returns whether the client can use delete items packets.
- *
- * @return whether the client can use delete items packets
- */
- boolean canUseDeletePackets();
-
- /**
- * Returns whether the client can use move items packets.
- *
- * @return whether the client can use move items packets
- */
- boolean canUseMovePackets();
}
}
diff --git a/build.gradle b/build.gradle
index cf405fcd5..501dcb541 100755
--- a/build.gradle
+++ b/build.gradle
@@ -47,6 +47,7 @@ allprojects {
":runtime-engine:views",
":runtime-engine:default-runtime-plugin",
":runtime-engine:initialization",
+ ":runtime-engine:networking",
":runtime-frontend:widgets",
":runtime-frontend:filtering",
":runtime-frontend:display",
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java
index f6d23677c..d4790e4b4 100644
--- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java
+++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java
@@ -23,15 +23,15 @@
package me.shedaniel.rei.plugin.autocrafting.recipebook;
-import me.shedaniel.rei.api.client.ClientHelper;
import me.shedaniel.rei.api.client.registry.transfer.TransferHandler;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay;
+import me.shedaniel.rei.api.common.networking.NetworkModule;
+import me.shedaniel.rei.api.common.networking.NetworkingHelper;
import me.shedaniel.rei.plugin.common.displays.cooking.DefaultCookingDisplay;
import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
-import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.inventory.CraftingMenu;
@@ -43,7 +43,7 @@ import net.minecraft.world.item.crafting.Recipe;
public class DefaultRecipeBookHandler implements TransferHandler {
@Override
public Result handle(Context context) {
- if (context.getDisplay() instanceof SimpleGridMenuDisplay && ClientHelper.getInstance().canUseMovePackets())
+ if (context.getDisplay() instanceof SimpleGridMenuDisplay && NetworkingHelper.getInstance().canUse(NetworkModule.TRANSFER))
return Result.createNotApplicable();
Display display = context.getDisplay();
if (!(context.getMenu() instanceof RecipeBookMenu<?> container))
diff --git a/runtime-engine/initialization/src/main/java/me/shedaniel/rei/impl/common/init/CoreInitialization.java b/runtime-engine/initialization/src/main/java/me/shedaniel/rei/impl/common/init/CoreInitialization.java
index 13a392e59..fc6304272 100644
--- a/runtime-engine/initialization/src/main/java/me/shedaniel/rei/impl/common/init/CoreInitialization.java
+++ b/runtime-engine/initialization/src/main/java/me/shedaniel/rei/impl/common/init/CoreInitialization.java
@@ -32,6 +32,7 @@ import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry;
import me.shedaniel.rei.api.common.entry.settings.EntrySettingsAdapterRegistry;
import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry;
import me.shedaniel.rei.api.common.fluid.FluidSupportProvider;
+import me.shedaniel.rei.api.common.networking.NetworkingHelper;
import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.api.common.plugins.REIPlugin;
import me.shedaniel.rei.api.common.plugins.REIServerPlugin;
@@ -70,6 +71,7 @@ public class CoreInitialization {
manager.registerReloadable(DisplaySerializerRegistry.class);
manager.registerReloadable(FluidSupportProvider.class);
PluginManager<REIServerPlugin> serverManager = PluginManager.getServerInstance();
+ serverManager.registerReloadable(NetworkingHelper.class);
serverManager.registerReloadable(MenuInfoRegistry.class);
Internals.attachInstance((Runnable) () -> reloadPlugins(null, null), "reloadREI");
}
diff --git a/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/impl/common/transfer/REITransferNetwork.java b/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/impl/common/transfer/TransferNetworkModule.java
index 357bddfa9..fe7cde2f7 100644
--- a/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/impl/common/transfer/REITransferNetwork.java
+++ b/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/impl/common/transfer/TransferNetworkModule.java
@@ -25,11 +25,14 @@ package me.shedaniel.rei.impl.common.transfer;
import dev.architectury.networking.NetworkManager;
import dev.architectury.networking.transformers.SplitPacketTransformer;
+import io.netty.buffer.Unpooled;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
-import me.shedaniel.rei.impl.common.networking.NetworkModule;
+import me.shedaniel.rei.api.common.networking.NetworkModule;
+import me.shedaniel.rei.api.common.networking.NetworkModuleKey;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
+import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
@@ -39,22 +42,22 @@ import net.minecraft.world.inventory.RecipeBookMenu;
import java.util.Collections;
-public class REITransferNetwork implements NetworkModule {
- public static final ResourceLocation MOVE_ITEMS_PACKET = new ResourceLocation("roughlyenoughitems", "move_items");
+public class TransferNetworkModule implements NetworkModule<NetworkModule.TransferData> {
+ public static final ResourceLocation ID = new ResourceLocation("roughlyenoughitems", "move_items");
@Override
- public Object getKey() {
+ public NetworkModuleKey<NetworkModule.TransferData> getKey() {
return NetworkModule.TRANSFER;
}
@Override
- public boolean canUse() {
- return NetworkManager.canServerReceive(REITransferNetwork.MOVE_ITEMS_PACKET);
+ public boolean canUse(Object target) {
+ return NetworkManager.canServerReceive(TransferNetworkModule.ID);
}
@Override
public void onInitialize() {
- NetworkManager.registerReceiver(NetworkManager.c2s(), MOVE_ITEMS_PACKET, Collections.singletonList(new SplitPacketTransformer()), (packetByteBuf, context) -> {
+ NetworkManager.registerReceiver(NetworkManager.c2s(), ID, Collections.singletonList(new SplitPacketTransformer()), (packetByteBuf, context) -> {
ServerPlayer player = (ServerPlayer) context.getPlayer();
CategoryIdentifier<Display> category = CategoryIdentifier.of(packetByteBuf.readResourceLocation());
AbstractContainerMenu container = player.containerMenu;
@@ -88,4 +91,14 @@ public class REITransferNetwork implements NetworkModule {
}
});
}
+
+ @Override
+ public void send(Object target, TransferData data) {
+ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
+ buf.writeResourceLocation(data.categoryIdentifier().getIdentifier());
+ buf.writeBoolean(data.stacked());
+
+ buf.writeNbt(data.displayTag());
+ NetworkManager.sendToServer(TransferNetworkModule.ID, buf);
+ }
}
diff --git a/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java b/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java
index 096b36879..14f685906 100644
--- a/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java
+++ b/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java
@@ -23,17 +23,16 @@
package me.shedaniel.rei.plugin.autocrafting;
-import dev.architectury.networking.NetworkManager;
-import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.ints.IntSet;
-import me.shedaniel.rei.api.client.ClientHelper;
import me.shedaniel.rei.api.client.registry.transfer.TransferHandler;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.InputIngredient;
+import me.shedaniel.rei.api.common.networking.NetworkModule;
+import me.shedaniel.rei.api.common.networking.NetworkingHelper;
import me.shedaniel.rei.api.common.transfer.RecipeFinder;
import me.shedaniel.rei.api.common.transfer.info.MenuInfo;
import me.shedaniel.rei.api.common.transfer.info.MenuInfoContext;
@@ -41,13 +40,11 @@ import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry;
import me.shedaniel.rei.api.common.transfer.info.MenuTransferException;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.EntryIngredients;
-import me.shedaniel.rei.impl.common.transfer.REITransferNetwork;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener;
-import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
@@ -96,7 +93,7 @@ public class DefaultCategoryHandler implements TransferHandler {
})
.tooltipMissing(CollectionUtils.map(missing, ingredient -> EntryIngredients.ofItemStacks(ingredient.get())));
}
- if (!ClientHelper.getInstance().canUseMovePackets()) {
+ if (!NetworkingHelper.getInstance().canUse(NetworkModule.TRANSFER)) {
return Result.createFailed(new TranslatableComponent("error.rei.not.on.server"));
}
if (!context.isActuallyCrafting()) {
@@ -107,12 +104,10 @@ public class DefaultCategoryHandler implements TransferHandler {
if (containerScreen instanceof RecipeUpdateListener listener) {
listener.getRecipeBookComponent().ghostRecipe.clear();
}
- FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
- buf.writeResourceLocation(display.getCategoryIdentifier().getIdentifier());
- buf.writeBoolean(context.isStackedCrafting());
-
- buf.writeNbt(menuInfo.save(menuInfoContext, display));
- NetworkManager.sendToServer(REITransferNetwork.MOVE_ITEMS_PACKET, buf);
+ NetworkingHelper.getInstance().sendToServer(NetworkModule.TRANSFER,
+ new NetworkModule.TransferData(display.getCategoryIdentifier(),
+ context.isStackedCrafting(),
+ menuInfo.save(menuInfoContext, display)));
return Result.createSuccessful();
}
diff --git a/runtime-engine/menu-info/src/main/resources/META-INF/services/me.shedaniel.rei.api.common.networking.NetworkModule b/runtime-engine/menu-info/src/main/resources/META-INF/services/me.shedaniel.rei.api.common.networking.NetworkModule
new file mode 100644
index 000000000..86049f550
--- /dev/null
+++ b/runtime-engine/menu-info/src/main/resources/META-INF/services/me.shedaniel.rei.api.common.networking.NetworkModule
@@ -0,0 +1 @@
+me.shedaniel.rei.impl.common.transfer.TransferNetworkModule \ No newline at end of file
diff --git a/runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/client/networking/modules/CheatItemStatusNetworkModule.java b/runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/client/networking/modules/CheatItemStatusNetworkModule.java
new file mode 100644
index 000000000..45c687cdf
--- /dev/null
+++ b/runtime-engine/networking/src/main/java/me/shedaniel/rei/impl/client/networking/modules/CheatItemStatusNetworkModule.java
@@ -0,0 +1,78 @@
+/*
+ * 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.impl.client.networking.modules;
+
+import dev.architectury.networking.NetworkManager;
+import dev.architectury.networking.transformers.SplitPacketTransformer;
+import dev.architectury.utils.Env;
+import dev.architectury.utils.EnvExecutor;
+import io.netty.buffer.Unpooled;
+import me.shedaniel.rei.api.common.networking.NetworkModule;
+import me.shedaniel.rei.api.common.networking.NetworkModuleKey;
+import me.shedaniel.rei.api.common.util.EntryStacks;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.resources.language.I18n;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.chat.TextComponent;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.item.ItemStack;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class CheatItemStatusNetworkModule implements NetworkModule<Map.Entry<ItemStack, String>> {
+ public static final ResourceLocation ID = new ResourceLocation("roughlyenoughitems", "ci_msg");
+
+ @Override
+ public NetworkModuleKey<Map.Entry<ItemStack, String>> getKey() {
+ return NetworkModule.CHEAT_STATUS_REPLY;
+ }
+
+ @Override
+ public boolean canUse(Object target) {
+ return NetworkManager.canPlayerReceive((ServerPlayer) target, CheatItemStatusNetworkModule.ID);
+ }
+
+ @Override
+ public void onInitialize() {
+ EnvExecutor.runInEnv(Env.CLIENT, () -> () -> {
+ NetworkManager.registerReceiver(NetworkManager.c2s(), ID, Collections.singletonList(new SplitPacketTransformer()), (buf, context) -> {
+ ItemStack stack = buf.readItem();
+ String player = buf.readUtf(32767);
+ if (Minecraft.getInstance().player != null) {
+ Minecraft.getInstance().player.displayClientMessage(new TextComponent(I18n.get("text.rei.cheat_items").replaceAll("\\{item_name}", EntryStacks.of(stack.copy()).asFormattedText().getString()).replaceAll("\\{item_count}", stack.copy().getCount() + "").replaceAll("\\{player_name}", player)), false);
+ }
+ });
+ });
+ }
+
+ @Override
+ public void send(Object target, Map.Entry<ItemStack, String> data) {
+ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
+ buf.writeItem(data.getKey().copy());