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 class BackpackInventory implements Inventory {
|
||||||
public static final int SECTION_SIZE = 9;
|
public static final int SECTION_SIZE = 9;
|
||||||
private final DefaultedList<ItemStack> stacks;
|
private final DefaultedList<ItemStack> stacks;
|
||||||
public final PlayerEntity accessor;
|
|
||||||
private BackpackScreenHandler container;
|
private BackpackScreenHandler container;
|
||||||
|
|
||||||
public BackpackInventory(BackpackScreenHandler container, PlayerEntity player) {
|
public BackpackInventory(BackpackScreenHandler container) {
|
||||||
this.accessor = player;
|
|
||||||
this.stacks = DefaultedList.ofSize(SECTION_SIZE * ItemBackpack.SLOTSIZE, ItemStack.EMPTY);
|
this.stacks = DefaultedList.ofSize(SECTION_SIZE * ItemBackpack.SLOTSIZE, ItemStack.EMPTY);
|
||||||
this.container = container;
|
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 TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/backpack.png");
|
||||||
private final static Identifier SLOT_TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/slot.png");
|
private final static Identifier SLOT_TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/slot.png");
|
||||||
private int slots;
|
private int slots;
|
||||||
private Integer containerHeight;
|
private final Integer containerHeight = 222;
|
||||||
private Integer containerWidth;
|
private final Integer containerWidth = 176;
|
||||||
|
|
||||||
public BackpackScreen(BackpackScreenHandler handler, PlayerInventory inventory, Text text) {
|
public BackpackScreen(BackpackScreenHandler handler, PlayerInventory inventory, Text text) {
|
||||||
super(handler, inventory, new TranslatableText("container.quickiefabric.backpack"));
|
super(handler, inventory, new TranslatableText("container.quickiefabric.backpack"));
|
||||||
slots = ItemBackpack.SLOTSIZE;
|
slots = ItemBackpack.SLOTSIZE;
|
||||||
if ((slots / 9) == 4) {
|
|
||||||
this.containerHeight = 184;
|
|
||||||
} else if ((slots / 9) > 4) {
|
|
||||||
this.containerHeight = 222;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,59 +14,42 @@ import net.minecraft.util.collection.DefaultedList;
|
|||||||
|
|
||||||
public class BackpackScreenHandler extends ScreenHandler {
|
public class BackpackScreenHandler extends ScreenHandler {
|
||||||
|
|
||||||
private final BackpackInventory inv;
|
private final BackpackInventory backpackInventory;
|
||||||
private final PlayerEntity player;
|
private final PlayerEntity player;
|
||||||
private int backpackSlots;
|
private int backpackSlots;
|
||||||
private Hand hand;
|
private Hand hand;
|
||||||
|
|
||||||
public BackpackScreenHandler(int syncId, PlayerInventory playerInv) {
|
public BackpackScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||||
super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId);
|
super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId);
|
||||||
this.inv = new BackpackInventory(this, playerInv.player);
|
this.player = playerInventory.player;
|
||||||
this.player = playerInv.player;
|
this.backpackInventory = new BackpackInventory(this);
|
||||||
this.hand = player.getActiveHand();
|
|
||||||
backpackSlots = ItemBackpack.SLOTSIZE;
|
backpackSlots = ItemBackpack.SLOTSIZE;
|
||||||
|
|
||||||
int spacing;
|
int spacing;
|
||||||
if(backpackSlots % 9 == 0)
|
if (backpackSlots % 9 == 0) {
|
||||||
spacing = 30 + (backpackSlots /9) * 18 + ((backpackSlots /9) < 5 ? 0 : 2);
|
spacing = 30 + (backpackSlots / 9) * 18 + ((backpackSlots / 9) < 5 ? 0 : 2);
|
||||||
else
|
} else {
|
||||||
spacing = 30 + (backpackSlots /9 + 1) * 18 + ((backpackSlots /9) < 5 ? 0 : 2);
|
spacing = 30 + (backpackSlots / 9 + 1) * 18 + ((backpackSlots / 9) < 5 ? 0 : 2);
|
||||||
|
}
|
||||||
for(int y = 0; y < (backpackSlots /9); y++) {
|
for (int y = 0; y < (backpackSlots / 9); y++) {
|
||||||
for(int x = 0; x < 9; ++x) {
|
for (int x = 0; x < 9; ++x) {
|
||||||
this.addSlot(new Slot(inv, x + y * 9, 8 + x * 18, 18 + y * 18));
|
this.addSlot(new Slot(backpackInventory, x + y * 9, 8 + x * 18, 18 + y * 18));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((backpackSlots % 9) != 0)
|
if ((backpackSlots % 9) != 0) {
|
||||||
for(int x = 0; x < (backpackSlots % 9); x++) {
|
for (int x = 0; x < (backpackSlots % 9); x++) {
|
||||||
this.addSlot(new Slot(inv, x + (backpackSlots /9) * 9, 8 + x * 18, 18 + (backpackSlots /9) * 18));
|
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) {
|
||||||
for(int y = 0; y < 3; ++y) {
|
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 + y * 9 + 9, 8 + x * 18, spacing + y * 18));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (int x = 0; x < 9; ++x) {
|
||||||
for(int x = 0; x < 9; ++x) {
|
this.addSlot(new Slot(playerInventory, x, 8 + x * 18, 58 + spacing));
|
||||||
this.addSlot(new Slot(playerInv, 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
|
@Override
|
||||||
@ -76,14 +59,14 @@ public class BackpackScreenHandler extends ScreenHandler {
|
|||||||
|
|
||||||
public void onContentChanged(Inventory inv) {
|
public void onContentChanged(Inventory inv) {
|
||||||
super.onContentChanged(inv);
|
super.onContentChanged(inv);
|
||||||
if (inv == this.inv) {
|
if (inv == this.backpackInventory) {
|
||||||
this.updateInv();
|
this.updateInv();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close(PlayerEntity player) {
|
public void close(PlayerEntity player) {
|
||||||
super.close(player);
|
super.close(player);
|
||||||
this.inv.onClose(player);
|
this.backpackInventory.onClose(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateInv() {
|
public void updateInv() {
|
||||||
@ -116,11 +99,30 @@ public class BackpackScreenHandler extends ScreenHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onSlotClick(int int_1, int int_2, SlotActionType slotActionType_1, PlayerEntity playerEntity_1) {
|
public ItemStack onSlotClick(int i, int j, SlotActionType slotActionType, PlayerEntity playerEntity) {
|
||||||
if(int_1 > 0) {
|
if (i > 0) {
|
||||||
if (this.getSlot(int_1).getStack().equals(playerEntity_1.getStackInHand(hand)))
|
if (this.getSlot(i).getStack().equals(playerEntity.getStackInHand(hand))) {
|
||||||
return ItemStack.EMPTY;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class ItemBackpack extends Item implements DyeableItem {
|
|||||||
LOGGER.info("found registered screen {}", id.toString());
|
LOGGER.info("found registered screen {}", id.toString());
|
||||||
}
|
}
|
||||||
SimpleNamedScreenHandlerFactory factory = new SimpleNamedScreenHandlerFactory(
|
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()));
|
Text.method_30163(RegistryManager.BACKPACK_CONTAINTER.toString()));
|
||||||
player.openHandledScreen(factory);
|
player.openHandledScreen(factory);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"id": "quickiefabric",
|
"id": "quickiefabric",
|
||||||
"version": "${version}",
|
"version": "${version}",
|
||||||
|
|
||||||
"name": "quickiefabric",
|
"name": "quickiefabric",
|
||||||
"description": "Quickiefabric is the fabric implementation of Quickie, a mot to speed up daily work in Minecraft.",
|
"description": "Quickiefabric is the fabric implementation of Quickie, a mot to speed up daily work in Minecraft.",
|
||||||
"authors": [
|
"authors": [
|
||||||
@ -12,14 +11,15 @@
|
|||||||
"homepage": "https://gitlab.com/jottyfan/quickiefabric",
|
"homepage": "https://gitlab.com/jottyfan/quickiefabric",
|
||||||
"sources": "https://gitlab.com/jottyfan/quickiefabric"
|
"sources": "https://gitlab.com/jottyfan/quickiefabric"
|
||||||
},
|
},
|
||||||
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"icon": "assets/quickiefabric/icon.png",
|
"icon": "assets/quickiefabric/icon.png",
|
||||||
|
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"main": [
|
"main": [
|
||||||
"de.jottyfan.minecraft.quickiefabric.QuickieFabric"
|
"de.jottyfan.minecraft.quickiefabric.QuickieFabric"
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"de.jottyfan.minecraft.quickiefabric.QuickieFabricClient"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user