|
| 1 | +/* |
| 2 | + * This file is part of Sponge, licensed under the MIT License (MIT). |
| 3 | + * |
| 4 | + * Copyright (c) SpongePowered <https://www.spongepowered.org> |
| 5 | + * Copyright (c) contributors |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in |
| 15 | + * all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + * THE SOFTWARE. |
| 24 | + */ |
| 25 | +package org.spongepowered.common.mixin.inventory.impl.server.level; |
| 26 | + |
| 27 | +import net.minecraft.core.NonNullList; |
| 28 | +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; |
| 29 | +import net.minecraft.server.level.ServerPlayer; |
| 30 | +import net.minecraft.world.inventory.AbstractContainerMenu; |
| 31 | +import net.minecraft.world.item.ItemStack; |
| 32 | +import org.spongepowered.asm.mixin.Final; |
| 33 | +import org.spongepowered.asm.mixin.Mixin; |
| 34 | +import org.spongepowered.asm.mixin.Shadow; |
| 35 | +import org.spongepowered.asm.mixin.injection.At; |
| 36 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 37 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 38 | +import org.spongepowered.common.inventory.adapter.impl.slots.SlotAdapter; |
| 39 | +import org.spongepowered.common.item.util.ItemStackUtil; |
| 40 | + |
| 41 | +@Mixin(targets = "net/minecraft/server/level/ServerPlayer$1") |
| 42 | +public abstract class ServerPlayer_Mixin_Inventory { |
| 43 | + |
| 44 | + // @formatter:off |
| 45 | + @Shadow @Final ServerPlayer this$0; |
| 46 | + // @formatter:on |
| 47 | + |
| 48 | + @Inject(method = "sendInitialData", at = @At("RETURN")) |
| 49 | + private void inventory$sendOffhand(final AbstractContainerMenu containerMenu, final NonNullList<ItemStack> $$1, final ItemStack $$2, final int[] $$3, final CallbackInfo ci) { |
| 50 | + if (containerMenu == this.this$0.inventoryMenu) { |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + final org.spongepowered.api.item.inventory.Slot offhand |
| 55 | + = ((org.spongepowered.api.entity.living.player.server.ServerPlayer) this.this$0).inventory().offhand(); |
| 56 | + this.this$0.connection.send( |
| 57 | + new ClientboundContainerSetSlotPacket(-2, 0, ((SlotAdapter) offhand).getOrdinal(), ItemStackUtil.toNative(offhand.peek()))); |
| 58 | + } |
| 59 | +} |
0 commit comments