diff options
Diffstat (limited to 'runtime-engine')
7 files changed, 196 insertions, 26 deletions
diff --git a/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.java b/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.java index 8fc1e0a9b..46aab7972 100644 --- a/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.java +++ b/runtime-engine/categories/src/main/java/me/shedaniel/rei/impl/common/category/CategoryIdentifierImpl.java @@ -31,7 +31,7 @@ import org.jetbrains.annotations.ApiStatus; import java.util.Objects; @ApiStatus.Internal -class CategoryIdentifierImpl<D extends Display> implements CategoryIdentifier<D> { +final class CategoryIdentifierImpl<D extends Display> implements CategoryIdentifier<D> { private final ResourceLocation location; private final int hashCode; diff --git a/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultRuntimeInputMethodPlugin.java b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultRuntimeInputMethodPlugin.java new file mode 100644 index 000000000..f5434a0ad --- /dev/null +++ b/runtime-engine/default-runtime-plugin/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultRuntimeInputMethodPlugin.java @@ -0,0 +1,45 @@ +/* + * 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.client.runtime; + +import dev.architectury.platform.Platform; +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.search.method.InputMethodRegistry; +import me.shedaniel.rei.impl.client.search.method.unihan.BomopofoInputMethod; +import me.shedaniel.rei.impl.client.search.method.unihan.JyutpingInputMethod; +import me.shedaniel.rei.impl.client.search.method.unihan.PinyinInputMethod; +import me.shedaniel.rei.impl.client.search.method.unihan.UniHanManager; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public class DefaultRuntimeInputMethodPlugin implements REIClientPlugin { + @Override + public void registerInputMethods(InputMethodRegistry registry) { + UniHanManager manager = new UniHanManager(Platform.getConfigFolder().resolve("roughlyenoughitems/unihan.zip")); + registry.add(new ResourceLocation("rei:pinyin"), new PinyinInputMethod(manager)); + registry.add(new ResourceLocation("rei:jyutping"), new JyutpingInputMethod(manager)); + registry.add(new ResourceLocation("rei:bomopofo"), new BomopofoInputMethod(manager)); + } +} 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()); + } +} diff --git a/runtime-engine/views/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java b/runtime-engine/views/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java index c0e6381e9..1ba0b9e4f 100644 --- a/runtime-engine/views/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java +++ b/runtime-engine/views/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java @@ -53,9 +53,9 @@ import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.api.common.util.EntryStacks; -import me.shedaniel.rei.impl.client.view.craftable.CraftableFilter; import me.shedaniel.rei.impl.client.gui.widget.AutoCraftingEvaluator; import me.shedaniel.rei.impl.client.util.CrashReportUtils; +import me.shedaniel.rei.impl.client.view.craftable.CraftableFilter; import me.shedaniel.rei.impl.common.InternalLogger; import me.shedaniel.rei.impl.display.DisplaySpec; import net.minecraft.CrashReport; @@ -87,13 +87,13 @@ public class ViewsImpl implements Views { BUILDER.set(builder); try { - return _buildMapFor(builder); + return ((ViewsImpl) Views.getInstance())._buildMapFor(builder); } finally { BUILDER.remove(); } } - private static Map<DisplayCategory<?>, List<DisplaySpec>> _buildMapFor(ViewSearchBuilder builder) { + private Map<DisplayCategory<?>, List<DisplaySpec>> _buildMapFor(ViewSearchBuilder builder) { if (PluginManager.areAnyReloading()) { InternalLogger.getInstance().info("Cancelled Views buildMap since plugins have not finished reloading."); return Maps.newLinkedHashMap(); @@ -290,11 +290,13 @@ public class ViewsImpl implements Views { return resultSpeced; } - public static boolean isRecipesFor(List<EntryStack<?>> stacks, Display display) { + @Override + public boolean isRecipesFor(List<EntryStack<?>> stacks, Display display) { return checkUsages(stacks, display, display.getOutputEntries()); } - public static boolean isUsagesFor(List<EntryStack<?>> stacks, Display display) { + @Override + public boolean isUsagesFor(List<EntryStack<?>> stacks, Display display) { return checkUsages(stacks, display, display.getInputEntries()); } diff --git a/runtime-engine/views/src/main/java/me/shedaniel/rei/impl/client/view/craftable/CraftableFilter.java b/runtime-engine/views/src/main/java/me/shedaniel/rei/impl/client/view/craftable/CraftableFilter.java index f81d0c385..f004bd0ed 100644 --- a/runtime-engine/views/src/main/java/me/shedaniel/rei/impl/client/view/craftable/CraftableFilter.java +++ b/runtime-engine/views/src/main/java/me/shedaniel/rei/impl/client/view/craftable/CraftableFilter.java @@ -26,6 +26,9 @@ package me.shedaniel.rei.impl.client.view.craftable; import it.unimi.dsi.fastutil.longs.Long2LongMap; import it.unimi.dsi.fastutil.longs.Long2LongMaps; import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap; +import me.shedaniel.rei.api.client.REIRuntime; +import me.shedaniel.rei.api.client.config.ConfigManager; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; import me.shedaniel.rei.api.common.entry.type.EntryDefinition; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; @@ -36,27 +39,17 @@ import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; +import java.util.Optional; + public class CraftableFilter { public static final CraftableFilter INSTANCE = new CraftableFilter(); - private boolean dirty = false; private Long2LongMap invStacks = new Long2LongOpenHashMap(); private Long2LongMap containerStacks = new Long2LongOpenHashMap(); - public void markDirty() { - dirty = true; - } - - public boolean wasDirty() { - if (dirty) { - dirty = false; - return true; - } - - return false; - } - public void tick() { - if (dirty) return; + Optional<ScreenOverlay> overlay = REIRuntime.getInstance().getOverlay(); + if (overlay.isEmpty() || overlay.get().isSearchReloadQueued()) return; + if (!ConfigManager.getInstance().isCraftableOnlyEnabled()) return; Long2LongMap currentStacks; try { currentStacks = getInventoryItemsTypes(); @@ -66,9 +59,9 @@ public class CraftableFilter { } if (!currentStacks.equals(this.invStacks)) { invStacks = currentStacks; - markDirty(); + overlay.ifPresent(ScreenOverlay::queueReloadSearch); + return; } - if (dirty) return; try { currentStacks = getContainerItemsTypes(); @@ -78,7 +71,7 @@ public class CraftableFilter { } if (!currentStacks.equals(this.containerStacks)) { containerStacks = currentStacks; - markDirty(); + overlay.ifPresent(ScreenOverlay::queueReloadSearch); } } |
