more backpack stuff

This commit is contained in:
Jörg Henke 2020-08-18 21:49:47 +02:00
parent 1303489a90
commit fd41db811b
3 changed files with 3 additions and 12 deletions

View File

@ -9,21 +9,20 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Hand;
import net.minecraft.util.collection.DefaultedList;
public class BackpackInventory implements Inventory {
public static final int SECTION_SIZE = 9;
private final DefaultedList<ItemStack> stacks;
private final BackpackScreenHandler handler;
public BackpackInventory(CompoundTag tag, BackpackScreenHandler handler) {
private BackpackInventory(CompoundTag tag, BackpackScreenHandler handler) {
this.handler = handler;
this.stacks = DefaultedList.ofSize(SECTION_SIZE * ItemBackpack.SLOTSIZE, ItemStack.EMPTY);
readItemsFromTag(this.stacks, tag);
}
public static BackpackInventory getInventory(BackpackScreenHandler handler, PlayerEntity player) {
public static final BackpackInventory getInventory(BackpackScreenHandler handler, PlayerEntity player) {
ItemStack stack = player.getMainHandStack();
if (stack != null) {
if (!stack.hasTag()) {

View File

@ -17,13 +17,11 @@ public class BackpackScreenHandler extends ScreenHandler {
private final BackpackInventory backpackInventory;
private final PlayerEntity player;
private int backpackSlots;
private Hand hand;
public BackpackScreenHandler(int syncId, PlayerInventory playerInventory, PacketByteBuf buf) {
super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId);
this.player = playerInventory.player;
ItemStack stack = buf.readItemStack();
this.hand = buf.readInt() == 0 ? Hand.MAIN_HAND : Hand.OFF_HAND;
this.backpackInventory = BackpackInventory.getInventory(this, player);
backpackSlots = ItemBackpack.SLOTSIZE;
@ -108,8 +106,4 @@ public class BackpackScreenHandler extends ScreenHandler {
}
return copy;
}
public Hand getHand() {
return hand;
}
}

View File

@ -39,7 +39,6 @@ public class ItemBackpack extends Item implements DyeableItem {
@Override
public void writeScreenOpeningData(ServerPlayerEntity serverPlayerEntity, PacketByteBuf packetByteBuf) {
packetByteBuf.writeItemStack(itemStack);
packetByteBuf.writeInt(hand.equals(Hand.MAIN_HAND) ? 0 : 1);
}
@Override
@ -51,7 +50,6 @@ public class ItemBackpack extends Item implements DyeableItem {
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeItemStack(itemStack);
buf.writeInt(hand.equals(Hand.MAIN_HAND) ? 0 : 1);
return new BackpackScreenHandler(syncId, inv, buf);
}
});