some steps forward

This commit is contained in:
Jörg Henke 2020-08-14 18:02:01 +02:00
parent 38458dd71d
commit 7995208175
5 changed files with 138 additions and 143 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -14,59 +14,42 @@ import net.minecraft.util.collection.DefaultedList;
public class BackpackScreenHandler extends ScreenHandler {
private final BackpackInventory inv;
private final BackpackInventory backpackInventory;
private final PlayerEntity player;
private int backpackSlots;
private Hand hand;
public BackpackScreenHandler(int syncId, PlayerInventory playerInv) {
public BackpackScreenHandler(int syncId, PlayerInventory playerInventory) {
super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId);
this.inv = new BackpackInventory(this, playerInv.player);
this.player = playerInv.player;
this.hand = player.getActiveHand();
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);
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) {
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(inv, x + (backpackSlots /9) * 9, 8 + x * 18, 18 + (backpackSlots /9) * 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(playerInv, x + y * 9 + 9, 8 + x * 18, spacing + y * 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(playerInv, x, 8 + x * 18, 58 + spacing));
for (int x = 0; x < 9; ++x) {
this.addSlot(new Slot(playerInventory, x, 8 + x * 18, 58 + spacing));
}
DefaultedList<ItemStack> ad = DefaultedList.ofSize(backpackSlots, ItemStack.EMPTY);
ItemBackpack.getInventory(player.getStackInHand(this.hand), ad);
if(ad.size() == 0)
return;
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));
}
}
@Override
@ -76,14 +59,14 @@ public class BackpackScreenHandler extends ScreenHandler {
public void onContentChanged(Inventory inv) {
super.onContentChanged(inv);
if (inv == this.inv) {
if (inv == this.backpackInventory) {
this.updateInv();
}
}
public void close(PlayerEntity player) {
super.close(player);
this.inv.onClose(player);
this.backpackInventory.onClose(player);
}
public void updateInv() {
@ -116,11 +99,30 @@ public class BackpackScreenHandler extends ScreenHandler {
}
@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)))
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(int_1, int_2, slotActionType_1, playerEntity_1);
}
return super.onSlotClick(i, j, slotActionType, playerEntity);
}
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;
}
}

View File

@ -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);
}

View File

@ -2,7 +2,6 @@
"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": [
@ -12,14 +11,15 @@
"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": [