|
| 1 | +package org.taiyitistmc.mixin.world.inventory; |
| 2 | + |
| 3 | +import net.minecraft.network.chat.Component; |
| 4 | +import net.minecraft.world.inventory.AbstractContainerMenu; |
| 5 | +import net.minecraft.world.inventory.ContainerSynchronizer; |
| 6 | +import net.minecraft.world.item.ItemStack; |
| 7 | +import org.bukkit.craftbukkit.entity.CraftHumanEntity; |
| 8 | +import org.bukkit.craftbukkit.inventory.CraftInventory; |
| 9 | +import org.bukkit.inventory.InventoryView; |
| 10 | +import org.spongepowered.asm.mixin.Mixin; |
| 11 | +import org.spongepowered.asm.mixin.Shadow; |
| 12 | +import org.spongepowered.asm.mixin.Unique; |
| 13 | +import org.spongepowered.asm.mixin.injection.At; |
| 14 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 15 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 16 | + |
| 17 | +import javax.annotation.Nullable; |
| 18 | + |
| 19 | +@Mixin(AbstractContainerMenu.class) |
| 20 | +public abstract class MixinAbstractContainerMenu { |
| 21 | + |
| 22 | + @Shadow |
| 23 | + private ItemStack remoteCarried; |
| 24 | + |
| 25 | + @Shadow |
| 26 | + @Nullable |
| 27 | + private ContainerSynchronizer synchronizer; |
| 28 | + |
| 29 | + @Shadow |
| 30 | + public abstract ItemStack getCarried(); |
| 31 | + |
| 32 | + @Unique |
| 33 | + private Component title; |
| 34 | + |
| 35 | + @Unique |
| 36 | + private InventoryView bukkitView; |
| 37 | + |
| 38 | + |
| 39 | + // This provides a fallback that returns null |
| 40 | + public InventoryView getBukkitView() { |
| 41 | + return this.bukkitView; |
| 42 | + } |
| 43 | + |
| 44 | + public void setBukkitView(InventoryView view) { |
| 45 | + this.bukkitView = view; |
| 46 | + } |
| 47 | + |
| 48 | + public void transferTo(AbstractContainerMenu other, CraftHumanEntity player) { |
| 49 | + InventoryView source = this.getBukkitView(); |
| 50 | + InventoryView destination = other.getBukkitView(); |
| 51 | + if (source != null) { |
| 52 | + ((CraftInventory) source.getTopInventory()).getInventory().onClose(player); |
| 53 | + ((CraftInventory) source.getBottomInventory()).getInventory().onClose(player); |
| 54 | + } |
| 55 | + if (destination != null) { |
| 56 | + ((CraftInventory) destination.getTopInventory()).getInventory().onOpen(player); |
| 57 | + ((CraftInventory) destination.getBottomInventory()).getInventory().onOpen(player); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + public Component getTitle() { |
| 62 | + if (this.title == null) { |
| 63 | + return Component.empty(); |
| 64 | + } |
| 65 | + return this.title; |
| 66 | + } |
| 67 | + |
| 68 | + public void setTitle(Component title) { |
| 69 | + this.title = title; |
| 70 | + } |
| 71 | + |
| 72 | + public void broadcastCarriedItem() { |
| 73 | + ItemStack carried = this.getCarried(); |
| 74 | + this.remoteCarried = carried.copy(); |
| 75 | + if (this.synchronizer != null) { |
| 76 | + this.synchronizer.sendCarriedChange((AbstractContainerMenu) (Object) this, carried.copy()); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments