aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java
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 /api/src/main/java
parentbb7920e447d599d23abfac3b67d8823cf24f8150 (diff)
downloadRoughlyEnoughItems-0ef0f8b21df4b9a603aaa2ab4a35d395ef6437c1.tar.gz
RoughlyEnoughItems-0ef0f8b21df4b9a603aaa2ab4a35d395ef6437c1.tar.bz2
RoughlyEnoughItems-0ef0f8b21df4b9a603aaa2ab4a35d395ef6437c1.zip
Make it not crash
Diffstat (limited to 'api/src/main/java')
-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.java27
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java39
4 files changed, 107 insertions, 17 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/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModuleKey.java b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModuleKey.java
new file mode 100644
index 000000000..155aff65a
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkModuleKey.java
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+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();
}
}