aboutsummaryrefslogtreecommitdiff
path: root/runtime-engine/menu-info/src/main/java/me
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-08-06 10:37:38 +0800
committershedaniel <daniel@shedaniel.me>2022-08-26 10:54:44 +0900
commitd3bfd79800aacfde6617d5430ead5fdda0a506fe (patch)
treeb8420034448bd3193c7f541f47a6387a9772d99f /runtime-engine/menu-info/src/main/java/me
parent8c13c015031a0de865d2e767cd8e879754f803e2 (diff)
downloadRoughlyEnoughItems-d3bfd79800aacfde6617d5430ead5fdda0a506fe.tar.gz
RoughlyEnoughItems-d3bfd79800aacfde6617d5430ead5fdda0a506fe.tar.bz2
RoughlyEnoughItems-d3bfd79800aacfde6617d5430ead5fdda0a506fe.zip
More work okay
Diffstat (limited to 'runtime-engine/menu-info/src/main/java/me')
-rw-r--r--runtime-engine/menu-info/src/main/java/me/shedaniel/rei/impl/common/transfer/REITransferNetwork.java91
-rw-r--r--runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java4
-rw-r--r--runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultClientTransferCategoryPlugin.java39
3 files changed, 132 insertions, 2 deletions
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/REITransferNetwork.java
new file mode 100644
index 000000000..357bddfa9
--- /dev/null
+++ b/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/impl/common/transfer/REITransferNetwork.java
@@ -0,0 +1,91 @@
+/*
+ * 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.common.transfer;
+
+import dev.architectury.networking.NetworkManager;
+import dev.architectury.networking.transformers.SplitPacketTransformer;
+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 net.minecraft.ChatFormatting;
+import net.minecraft.Util;
+import net.minecraft.network.chat.TranslatableComponent;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.inventory.AbstractContainerMenu;
+import net.minecraft.world.inventory.InventoryMenu;
+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");
+
+ @Override
+ public Object getKey() {
+ return NetworkModule.TRANSFER;
+ }
+
+ @Override
+ public boolean canUse() {
+ return NetworkManager.canServerReceive(REITransferNetwork.MOVE_ITEMS_PACKET);
+ }
+
+ @Override
+ public void onInitialize() {
+ NetworkManager.registerReceiver(NetworkManager.c2s(), MOVE_ITEMS_PACKET, Collections.singletonList(new SplitPacketTransformer()), (packetByteBuf, context) -> {
+ ServerPlayer player = (ServerPlayer) context.getPlayer();
+ CategoryIdentifier<Display> category = CategoryIdentifier.of(packetByteBuf.readResourceLocation());
+ AbstractContainerMenu container = player.containerMenu;
+ InventoryMenu playerContainer = player.inventoryMenu;
+ try {
+ boolean shift = packetByteBuf.readBoolean();
+ try {
+ InputSlotCrafter<AbstractContainerMenu, Display> crafter = InputSlotCrafter.start(category, container, player, packetByteBuf.readAnySizeNbt(), shift);
+ } catch (InputSlotCrafter.NotEnoughMaterialsException e) {
+ if (!(container instanceof RecipeBookMenu)) {
+ return;
+ }
+ // TODO Implement Ghost Recipes
+ /*FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
+ buf.writeInt(input.size());
+ for (List<ItemStack> stacks : input) {
+ buf.writeInt(stacks.size());
+ for (ItemStack stack : stacks) {
+ buf.writeItem(stack);
+ }
+ }
+ NetworkManager.sendToPlayer(player, NOT_ENOUGH_ITEMS_PACKET, buf);*/
+ } catch (IllegalStateException e) {
+ player.sendMessage(new TranslatableComponent(e.getMessage()).withStyle(ChatFormatting.RED), Util.NIL_UUID);
+ } catch (Exception e) {
+ player.sendMessage(new TranslatableComponent("error.rei.internal.error", e.getMessage()).withStyle(ChatFormatting.RED), Util.NIL_UUID);
+ e.printStackTrace();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
+ }
+}
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 3c1f69b29..096b36879 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
@@ -29,7 +29,6 @@ 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.RoughlyEnoughItemsNetwork;
import me.shedaniel.rei.api.client.ClientHelper;
import me.shedaniel.rei.api.client.registry.transfer.TransferHandler;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
@@ -42,6 +41,7 @@ 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;
@@ -112,7 +112,7 @@ public class DefaultCategoryHandler implements TransferHandler {
buf.writeBoolean(context.isStackedCrafting());
buf.writeNbt(menuInfo.save(menuInfoContext, display));
- NetworkManager.sendToServer(RoughlyEnoughItemsNetwork.MOVE_ITEMS_PACKET, buf);
+ NetworkManager.sendToServer(REITransferNetwork.MOVE_ITEMS_PACKET, buf);
return Result.createSuccessful();
}
diff --git a/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultClientTransferCategoryPlugin.java b/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultClientTransferCategoryPlugin.java
new file mode 100644
index 000000000..ac2f97861
--- /dev/null
+++ b/runtime-engine/menu-info/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultClientTransferCategoryPlugin.java
@@ -0,0 +1,39 @@
+/*
+ * 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.autocrafting;
+
+import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
+import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+import org.jetbrains.annotations.ApiStatus;
+
+@Environment(EnvType.CLIENT)
+@ApiStatus.Internal
+public class DefaultClientTransferCategoryPlugin implements REIClientPlugin {
+ @Override
+ public void registerTransferHandlers(TransferHandlerRegistry registry) {
+ registry.register(new DefaultCategoryHandler());
+ }
+}