more backpack stuff
This commit is contained in:
parent
1303489a90
commit
fd41db811b
@ -9,7 +9,6 @@ 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 {
|
||||
@ -17,13 +16,13 @@ public class BackpackInventory implements Inventory {
|
||||
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()) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user