diff options
| author | shedaniel <daniel@shedaniel.me> | 2023-08-28 13:16:57 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2023-09-01 19:48:57 +0800 |
| commit | 6a8bc6a8c34af1e3ff15fe8a802ef5ece3c417d2 (patch) | |
| tree | a41c145c1273ab063c725bf44c1f39ca6e0bd5bd /runtime/src/main/java/me/shedaniel/rei/plugin/common | |
| parent | f8bea2079764219f68070be9ae45ffd8d517de5d (diff) | |
| download | RoughlyEnoughItems-6a8bc6a8c34af1e3ff15fe8a802ef5ece3c417d2.tar.gz RoughlyEnoughItems-6a8bc6a8c34af1e3ff15fe8a802ef5ece3c417d2.tar.bz2 RoughlyEnoughItems-6a8bc6a8c34af1e3ff15fe8a802ef5ece3c417d2.zip | |
Reworked the transfer api
See https://www.craft.me/s/TVL01jO3OZarPE for the documentation of the new experimental simple transfer handle
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/plugin/common')
| -rw-r--r-- | runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java index 1fd0126d5..ca1e44846 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java @@ -30,10 +30,18 @@ import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; import me.shedaniel.rei.api.common.plugins.REIServerPlugin; +import me.shedaniel.rei.api.common.transfer.info.stack.PlayerInventorySlotAccessor; +import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor; +import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessorRegistry; +import me.shedaniel.rei.api.common.transfer.info.stack.VanillaSlotAccessor; import me.shedaniel.rei.plugin.client.entry.FluidEntryDefinition; import me.shedaniel.rei.plugin.client.entry.ItemEntryDefinition; +import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.Optional; import java.util.stream.Stream; @@ -55,4 +63,48 @@ public class DefaultRuntimePlugin implements REIServerPlugin { return CompoundEventResult.interruptTrue(stream.get()); }); } + + @Override + public void registerSlotAccessors(SlotAccessorRegistry registry) { + registry.register(new ResourceLocation("roughlyenoughitems", "vanilla"), + slotAccessor -> slotAccessor instanceof VanillaSlotAccessor, + new SlotAccessorRegistry.Serializer() { + @Override + public SlotAccessor read(AbstractContainerMenu menu, Player player, CompoundTag tag) { + int slot = tag.getInt("Slot"); + return new VanillaSlotAccessor(menu.slots.get(slot)); + } + + @Override + @Nullable + public CompoundTag save(AbstractContainerMenu menu, Player player, SlotAccessor accessor) { + if (!(accessor instanceof VanillaSlotAccessor)) { + throw new IllegalArgumentException("Cannot save non-vanilla slot accessor!"); + } + CompoundTag tag = new CompoundTag(); + tag.putInt("Slot", ((VanillaSlotAccessor) accessor).getSlot().index); + return tag; + } + }); + registry.register(new ResourceLocation("roughlyenoughitems", "player"), + slotAccessor -> slotAccessor instanceof PlayerInventorySlotAccessor, + new SlotAccessorRegistry.Serializer() { + @Override + public SlotAccessor read(AbstractContainerMenu menu, Player player, CompoundTag tag) { + int slot = tag.getInt("Slot"); + return new PlayerInventorySlotAccessor(player, slot); + } + + @Override + @Nullable + public CompoundTag save(AbstractContainerMenu menu, Player player, SlotAccessor accessor) { + if (!(accessor instanceof PlayerInventorySlotAccessor)) { + throw new IllegalArgumentException("Cannot save non-player slot accessor!"); + } + CompoundTag tag = new CompoundTag(); + tag.putInt("Slot", ((PlayerInventorySlotAccessor) accessor).getIndex()); + return tag; + } + }); + } } |
