some steps forward
This commit is contained in:
parent
38458dd71d
commit
7995208175
@ -10,11 +10,9 @@ import net.minecraft.util.collection.DefaultedList;
|
||||
public class BackpackInventory implements Inventory {
|
||||
public static final int SECTION_SIZE = 9;
|
||||
private final DefaultedList<ItemStack> stacks;
|
||||
public final PlayerEntity accessor;
|
||||
private BackpackScreenHandler container;
|
||||
|
||||
public BackpackInventory(BackpackScreenHandler container, PlayerEntity player) {
|
||||
this.accessor = player;
|
||||
public BackpackInventory(BackpackScreenHandler container) {
|
||||
this.stacks = DefaultedList.ofSize(SECTION_SIZE * ItemBackpack.SLOTSIZE, ItemStack.EMPTY);
|
||||
this.container = container;
|
||||
}
|
||||
|
@ -19,17 +19,12 @@ public class BackpackScreen extends HandledScreen<BackpackScreenHandler> impleme
|
||||
private final static Identifier TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/backpack.png");
|
||||
private final static Identifier SLOT_TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/slot.png");
|
||||
private int slots;
|
||||
private Integer containerHeight;
|
||||
private Integer containerWidth;
|
||||
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;
|
||||
if ((slots / 9) == 4) {
|
||||
this.containerHeight = 184;
|
||||
} else if ((slots / 9) > 4) {
|
||||
this.containerHeight = 222;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,113 +14,115 @@ import net.minecraft.util.collection.DefaultedList;
|
||||
|
||||
public class BackpackScreenHandler extends ScreenHandler {
|
||||
|
||||
private final BackpackInventory inv;
|
||||
private final PlayerEntity player;
|
||||
private int backpackSlots;
|
||||
private Hand hand;
|
||||
private final BackpackInventory backpackInventory;
|
||||
private final PlayerEntity player;
|
||||
private int backpackSlots;
|
||||
private Hand hand;
|
||||
|
||||
public BackpackScreenHandler(int syncId, PlayerInventory playerInv) {
|
||||
super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId);
|
||||
this.inv = new BackpackInventory(this, playerInv.player);
|
||||
this.player = playerInv.player;
|
||||
this.hand = player.getActiveHand();
|
||||
backpackSlots = ItemBackpack.SLOTSIZE;
|
||||
public BackpackScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId);
|
||||
this.player = playerInventory.player;
|
||||
this.backpackInventory = new BackpackInventory(this);
|
||||
backpackSlots = ItemBackpack.SLOTSIZE;
|
||||
|
||||
int spacing;
|
||||
if(backpackSlots % 9 == 0)
|
||||
spacing = 30 + (backpackSlots /9) * 18 + ((backpackSlots /9) < 5 ? 0 : 2);
|
||||
else
|
||||
spacing = 30 + (backpackSlots /9 + 1) * 18 + ((backpackSlots /9) < 5 ? 0 : 2);
|
||||
int spacing;
|
||||
if (backpackSlots % 9 == 0) {
|
||||
spacing = 30 + (backpackSlots / 9) * 18 + ((backpackSlots / 9) < 5 ? 0 : 2);
|
||||
} else {
|
||||
spacing = 30 + (backpackSlots / 9 + 1) * 18 + ((backpackSlots / 9) < 5 ? 0 : 2);
|
||||
}
|
||||
for (int y = 0; y < (backpackSlots / 9); y++) {
|
||||
for (int x = 0; x < 9; ++x) {
|
||||
this.addSlot(new Slot(backpackInventory, x + y * 9, 8 + x * 18, 18 + y * 18));
|
||||
}
|
||||
}
|
||||
if ((backpackSlots % 9) != 0) {
|
||||
for (int x = 0; x < (backpackSlots % 9); x++) {
|
||||
this.addSlot(
|
||||
new Slot(backpackInventory, x + (backpackSlots / 9) * 9, 8 + x * 18, 18 + (backpackSlots / 9) * 18));
|
||||
}
|
||||
for (int y = 0; y < 3; ++y) {
|
||||
for (int x = 0; x < 9; ++x) {
|
||||
this.addSlot(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, spacing + y * 18));
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < 9; ++x) {
|
||||
this.addSlot(new Slot(playerInventory, x, 8 + x * 18, 58 + spacing));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int y = 0; y < (backpackSlots /9); y++) {
|
||||
for(int x = 0; x < 9; ++x) {
|
||||
this.addSlot(new Slot(inv, x + y * 9, 8 + x * 18, 18 + y * 18));
|
||||
}
|
||||
}
|
||||
if((backpackSlots % 9) != 0)
|
||||
for(int x = 0; x < (backpackSlots % 9); x++) {
|
||||
this.addSlot(new Slot(inv, x + (backpackSlots /9) * 9, 8 + x * 18, 18 + (backpackSlots /9) * 18));
|
||||
}
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onContentChanged(Inventory inv) {
|
||||
super.onContentChanged(inv);
|
||||
if (inv == this.backpackInventory) {
|
||||
this.updateInv();
|
||||
}
|
||||
}
|
||||
|
||||
for(int y = 0; y < 3; ++y) {
|
||||
for(int x = 0; x < 9; ++x) {
|
||||
this.addSlot(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, spacing + y * 18));
|
||||
}
|
||||
}
|
||||
public void close(PlayerEntity player) {
|
||||
super.close(player);
|
||||
this.backpackInventory.onClose(player);
|
||||
}
|
||||
|
||||
for(int x = 0; x < 9; ++x) {
|
||||
this.addSlot(new Slot(playerInv, x, 8 + x * 18, 58 + spacing));
|
||||
}
|
||||
public void updateInv() {
|
||||
this.sendContentUpdates();
|
||||
}
|
||||
|
||||
DefaultedList<ItemStack> ad = DefaultedList.ofSize(backpackSlots, ItemStack.EMPTY);
|
||||
ItemBackpack.getInventory(player.getStackInHand(this.hand), ad);
|
||||
if(ad.size() == 0)
|
||||
return;
|
||||
@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 < backpackSlots) {
|
||||
if (!this.insertItem(clickedStack, backpackSlots, this.slots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.insertItem(clickedStack, 0, backpackSlots, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
for(int x = 0; x < 9; x++)
|
||||
for(int y = 0; y < backpackSlots /9; y++) {
|
||||
this.getSlot(x + y * 9).setStack(ad.get(x+y*9));
|
||||
}
|
||||
if (clickedStack.isEmpty()) {
|
||||
clickedSlot.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
clickedSlot.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
for(int x = 0; x < (backpackSlots % 9); x++) {
|
||||
this.getSlot(x + (backpackSlots /9)*9).setStack(ad.get(x+(backpackSlots /9)*9));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public ItemStack onSlotClick(int i, int j, SlotActionType slotActionType, PlayerEntity playerEntity) {
|
||||
if (i > 0) {
|
||||
if (this.getSlot(i).getStack().equals(playerEntity.getStackInHand(hand))) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
return super.onSlotClick(i, j, slotActionType, playerEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onContentChanged(Inventory inv) {
|
||||
super.onContentChanged(inv);
|
||||
if (inv == this.inv) {
|
||||
this.updateInv();
|
||||
}
|
||||
}
|
||||
|
||||
public void close(PlayerEntity player) {
|
||||
super.close(player);
|
||||
this.inv.onClose(player);
|
||||
}
|
||||
|
||||
public void updateInv() {
|
||||
this.sendContentUpdates();
|
||||
}
|
||||
|
||||
@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 < backpackSlots) {
|
||||
if (!this.insertItem(clickedStack, backpackSlots, this.slots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
} else if (!this.insertItem(clickedStack, 0, backpackSlots, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (clickedStack.isEmpty()) {
|
||||
clickedSlot.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
clickedSlot.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onSlotClick(int int_1, int int_2, SlotActionType slotActionType_1, PlayerEntity playerEntity_1) {
|
||||
if(int_1 > 0) {
|
||||
if (this.getSlot(int_1).getStack().equals(playerEntity_1.getStackInHand(hand)))
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return super.onSlotClick(int_1, int_2, slotActionType_1, playerEntity_1);
|
||||
}
|
||||
public BackpackScreenHandler withHand(Hand hand) {
|
||||
this.hand = hand;
|
||||
DefaultedList<ItemStack> ad = DefaultedList.ofSize(backpackSlots, ItemStack.EMPTY);
|
||||
ItemBackpack.getInventory(player.getStackInHand(this.hand), ad);
|
||||
if (ad.size() == 0) {
|
||||
return this;
|
||||
}
|
||||
for (int x = 0; x < 9; x++) {
|
||||
for (int y = 0; y < backpackSlots / 9; y++) {
|
||||
this.getSlot(x + y * 9).setStack(ad.get(x + y * 9));
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < (backpackSlots % 9); x++) {
|
||||
this.getSlot(x + (backpackSlots / 9) * 9).setStack(ad.get(x + (backpackSlots / 9) * 9));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class ItemBackpack extends Item implements DyeableItem {
|
||||
LOGGER.info("found registered screen {}", id.toString());
|
||||
}
|
||||
SimpleNamedScreenHandlerFactory factory = new SimpleNamedScreenHandlerFactory(
|
||||
(id, inventory, buf) -> new BackpackScreenHandler(id, player.inventory),
|
||||
(id, inventory, buf) -> new BackpackScreenHandler(id, player.inventory).withHand(hand),
|
||||
Text.method_30163(RegistryManager.BACKPACK_CONTAINTER.toString()));
|
||||
player.openHandledScreen(factory);
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "quickiefabric",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "quickiefabric",
|
||||
"description": "Quickiefabric is the fabric implementation of Quickie, a mot to speed up daily work in Minecraft.",
|
||||
"authors": [
|
||||
"Jottyfan"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://gitlab.com/jottyfan/quickiefabric",
|
||||
"sources": "https://gitlab.com/jottyfan/quickiefabric"
|
||||
},
|
||||
|
||||
"license": "MIT",
|
||||
"icon": "assets/quickiefabric/icon.png",
|
||||
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"de.jottyfan.minecraft.quickiefabric.QuickieFabric"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"quickiefabric.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"suggests": {
|
||||
"flamingo": "*"
|
||||
}
|
||||
"schemaVersion": 1,
|
||||
"id": "quickiefabric",
|
||||
"version": "${version}",
|
||||
"name": "quickiefabric",
|
||||
"description": "Quickiefabric is the fabric implementation of Quickie, a mot to speed up daily work in Minecraft.",
|
||||
"authors": [
|
||||
"Jottyfan"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://gitlab.com/jottyfan/quickiefabric",
|
||||
"sources": "https://gitlab.com/jottyfan/quickiefabric"
|
||||
},
|
||||
"license": "MIT",
|
||||
"icon": "assets/quickiefabric/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"de.jottyfan.minecraft.quickiefabric.QuickieFabric"
|
||||
],
|
||||
"client": [
|
||||
"de.jottyfan.minecraft.quickiefabric.QuickieFabricClient"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"quickiefabric.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"suggests": {
|
||||
"flamingo": "*"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user