backpack further steps
This commit is contained in:
parent
2a6e71b914
commit
f4550898a2
@ -21,13 +21,11 @@ public class BackpackScreen extends HandledScreen<BackpackScreenHandler>
|
||||
"textures/gui/backpack.png");
|
||||
private final static Identifier SLOT_TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC,
|
||||
"textures/gui/slot.png");
|
||||
private int slots;
|
||||
private final Integer containerHeight = 222;
|
||||
private final Integer containerWidth = 176;
|
||||
|
||||
public BackpackScreen(BackpackScreenHandler handler, PlayerInventory inventory, Text text) {
|
||||
super(handler, inventory, new TranslatableText("container.quickiefabric.backpack"));
|
||||
slots = ItemBackpack.SLOTSIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,14 +36,14 @@ public class BackpackScreen extends HandledScreen<BackpackScreenHandler>
|
||||
|
||||
private void drawSlots(MatrixStack matrices, int guiX, int guiY) {
|
||||
this.client.getTextureManager().bindTexture(SLOT_TEXTURE);
|
||||
for (int y = 0; y < (slots / 9); y++)
|
||||
for (int y = 0; y < (ItemBackpack.SLOTSIZE / 9); y++)
|
||||
for (int x = 0; x < 9; x++) {
|
||||
this.drawTexture(matrices, guiX + 7 + (x * 18), guiY + 17 + (y * 18), 0, 0, 18, 18);
|
||||
}
|
||||
|
||||
if ((slots % 9) != 0)
|
||||
for (int x = 0; x < (slots % 9); x++) {
|
||||
this.drawTexture(matrices, guiX + 7 + (x * 18), guiY + 17 + (slots / 9 * 18), 0, 0, 18, 18);
|
||||
if ((ItemBackpack.SLOTSIZE % 9) != 0)
|
||||
for (int x = 0; x < (ItemBackpack.SLOTSIZE % 9); x++) {
|
||||
this.drawTexture(matrices, guiX + 7 + (x * 18), guiY + 17 + (ItemBackpack.SLOTSIZE / 9 * 18), 0, 0, 18, 18);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.jottyfan.minecraft.quickiefabric.container;
|
||||
|
||||
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
|
||||
import de.jottyfan.minecraft.quickiefabric.items.ItemBackpack;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@ -15,16 +14,13 @@ public class BackpackScreenHandler extends ScreenHandler {
|
||||
private final BackpackInventory backpackInventory;
|
||||
private final PlayerEntity player;
|
||||
private final Hand hand;
|
||||
private final ItemStack stack; // the stack of the backpack item
|
||||
private int backpackSlotSize;
|
||||
|
||||
public BackpackScreenHandler(int syncId, PlayerInventory playerInventory, PacketByteBuf buf) {
|
||||
super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId);
|
||||
this.player = playerInventory.player;
|
||||
this.stack = buf.readItemStack();
|
||||
ItemStack stack = buf.readItemStack();
|
||||
this.hand = buf.readByte() > 0 ? Hand.MAIN_HAND : Hand.OFF_HAND;
|
||||
this.backpackInventory = BackpackInventory.getInventory(this, player, stack);
|
||||
backpackSlotSize = ItemBackpack.SLOTSIZE;
|
||||
|
||||
int spacing = 112;
|
||||
|
||||
@ -49,8 +45,8 @@ public class BackpackScreenHandler extends ScreenHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
return true;
|
||||
public boolean canUse(PlayerEntity playerEntity) {
|
||||
return backpackInventory.canPlayerUse(playerEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,27 +59,23 @@ public class BackpackScreenHandler extends ScreenHandler {
|
||||
@Override
|
||||
public ItemStack transferSlot(PlayerEntity player, int slotNum) {
|
||||
ItemStack copy = ItemStack.EMPTY;
|
||||
Slot clickedSlot = this.slots.get(slotNum);
|
||||
if (clickedSlot != null && clickedSlot.hasStack()) {
|
||||
ItemStack clickedStack = clickedSlot.getStack();
|
||||
copy = clickedStack.copy();
|
||||
if (slotNum < backpackSlotSize) {
|
||||
if (!this.insertItem(clickedStack, backpackSlotSize, this.slots.size(), true)) {
|
||||
Slot chosenSlot = this.slots.get(slotNum);
|
||||
if (chosenSlot != null && chosenSlot.hasStack()) {
|
||||
ItemStack chosenStack = chosenSlot.getStack();
|
||||
copy = chosenStack.copy();
|
||||
if (slotNum < backpackInventory.size()) {
|
||||
if (!this.insertItem(chosenStack, backpackInventory.size(), this.slots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.insertItem(clickedStack, 0, backpackSlotSize, false)) {
|
||||
} else if (!this.insertItem(chosenStack, 0, backpackInventory.size(), false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (clickedStack.isEmpty()) {
|
||||
clickedSlot.setStack(ItemStack.EMPTY);
|
||||
if (chosenStack.isEmpty()) {
|
||||
chosenSlot.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
clickedSlot.markDirty();
|
||||
chosenSlot.markDirty();
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user