Skip to content

Commit

Permalink
fix: incorrect inventory slot ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTJP committed Feb 1, 2023
1 parent bac383d commit f57712e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,4 @@ public boolean canConductorWork() {
public boolean isFlowFull() {
return condFlow == -1; // TODO same as above
}

//region Utils
protected void addPlayerInventory(PlayerInventory playerInventory, int x, int y) {
addInventory(playerInventory, 9, x, y, 9, 3); // Inventory (0 - 26)
addInventory(playerInventory, 0, x, y + 58, 9, 1); // Hotbar slots (27 - 35)
}

protected void addInventory(IInventory inventory, int i, int x, int y, int columns, int rows) {
addInventory(inventory, i, x, y, columns, rows, Slot::new);
}

protected void addInventory(IInventory inventory, int i, int x, int y, int columns, int rows, SlotFactory slotFactory) {
for (int c = 0; c < columns; c++) {
for (int r = 0; r < rows; r++) {
addSlot(slotFactory.createSlot(inventory, i + (r * columns + c), x + c * 18, y + r * 18));
}
}
}

@FunctionalInterface
protected interface SlotFactory {
Slot createSlot(IInventory inventory, int index, int x, int y);
}
//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import codechicken.lib.inventory.container.ICCLContainerFactory;
import mrtjp.projectred.core.CoreContent;
import mrtjp.projectred.core.tile.ElectrotineGeneratorTile;
import mrtjp.projectred.lib.InventoryLib;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
Expand All @@ -30,7 +32,7 @@ public ElectrotineGeneratorContainer(PlayerInventory playerInventory, Electrotin
this.playerInventory = playerInventory;
this.tile = tile;

addPlayerInventory(playerInventory, 8, 89);
InventoryLib.addPlayerInventory(playerInventory, 8, 89, this::addSlot);
addElectrotineGeneratorInventory();
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/scala/mrtjp/projectred/lib/InventoryLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public static void addInventory(IInventory inventory, int i, int x, int y, int c
* @param slotConsumer Consumer for the slots (typically Container.addSlot(...))
*/
public static void addInventory(IInventory inventory, int i, int x, int y, int columns, int rows, SlotFactory slotFactory, Consumer<Slot> slotConsumer) {
for (int c = 0; c < columns; c++) {
for (int r = 0; r < rows; r++) {
for (int r = 0; r < rows; r++) {
for (int c = 0; c < columns; c++) {
slotConsumer.accept(slotFactory.createSlot(inventory, i + (r * columns + c), x + c * 18, y + r * 18));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import mrtjp.projectred.expansion.init.ExpansionReferences;
import mrtjp.projectred.expansion.item.RecipePlanItem;
import mrtjp.projectred.expansion.tile.AutoCrafterTile;
import mrtjp.projectred.lib.InventoryLib;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
Expand All @@ -30,17 +32,17 @@ public AutoCrafterContainer(PlayerInventory inventory, AutoCrafterTile tile, int
this.playerInventory = inventory;
this.tile = tile;

addPlayerInventory(inventory, 8, 130);
InventoryLib.addPlayerInventory(inventory, 8, 130, this::addSlot);
addAutoCrafterInventory();
}

private void addAutoCrafterInventory() {

// Storage slot
addInventory(tile.getStorageInventory(), 0, 8, 80, 9, 2);
InventoryLib.addInventory(tile.getStorageInventory(), 0, 8, 80, 9, 2, this::addSlot);

// Plan grid
addInventory(tile.getPlanInventory(), 0, 44, 22, 3, 3, PlanSlot::new);
InventoryLib.addInventory(tile.getPlanInventory(), 0, 44, 22, 3, 3, PlanSlot::new, this::addSlot);
}

public AutoCrafterTile getAutoCrafterTile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mrtjp.projectred.expansion.item.IChargable;
import mrtjp.projectred.expansion.item.IRechargableBattery;
import mrtjp.projectred.expansion.tile.BatteryBoxTile;
import mrtjp.projectred.lib.InventoryLib;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
Expand Down Expand Up @@ -33,7 +34,7 @@ public BatteryBoxContainer(PlayerInventory inventory, BatteryBoxTile tile, int w
this.playerInventory = inventory;
this.tile = tile;

addPlayerInventory(inventory, 8, 89);
InventoryLib.addPlayerInventory(inventory, 8, 89, this::addSlot);
addBatteryBoxInventory();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mrtjp.projectred.expansion.init.ExpansionReferences;
import mrtjp.projectred.expansion.item.IChargable;
import mrtjp.projectred.expansion.tile.ChargingBenchTile;
import mrtjp.projectred.lib.InventoryLib;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
Expand Down Expand Up @@ -32,13 +33,13 @@ public ChargingBenchContainer(PlayerInventory inventory, ChargingBenchTile tile,
this.playerInventory = inventory;
this.tile = tile;

addPlayerInventory(inventory, 8, 101);
InventoryLib.addPlayerInventory(inventory, 8, 101, this::addSlot);
addChargingBenchInventory();
}

private void addChargingBenchInventory() {
addInventory(tile.getInventory(), 0, 88, 17, 4, 2, ChargeableItemSlot::new);
addInventory(tile.getInventory(), 8, 88, 57, 4, 2, ChargeableItemSlot::new);
InventoryLib.addInventory(tile.getInventory(), 0, 88, 17, 4, 2, ChargeableItemSlot::new, this::addSlot);
InventoryLib.addInventory(tile.getInventory(), 8, 88, 57, 4, 2, ChargeableItemSlot::new, this::addSlot);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import mrtjp.projectred.expansion.init.ExpansionReferences;
import mrtjp.projectred.expansion.item.RecipePlanItem;
import mrtjp.projectred.expansion.tile.ProjectBenchTile;
import mrtjp.projectred.lib.InventoryLib;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
Expand All @@ -29,17 +30,17 @@ public ProjectBenchContainer(PlayerInventory playerInventory, ProjectBenchTile t
this.playerInventory = playerInventory;
this.tile = tile;

addPlayerInventory(playerInventory, 8, 126);
InventoryLib.addPlayerInventory(playerInventory, 8, 126, this::addSlot);
addProjectBenchInventory();
}

private void addProjectBenchInventory() {

// Storage slots
addInventory(tile.getStorageInventory(), 0, 8, 76, 9, 2);
InventoryLib.addInventory(tile.getStorageInventory(), 0, 8, 76, 9, 2, this::addSlot);

// Crafting grid
addInventory(tile.getCraftingGridInventory(), 0, 48, 18, 3, 3);
InventoryLib.addInventory(tile.getCraftingGridInventory(), 0, 48, 18, 3, 3, this::addSlot);

// Result slot
addSlot(new ProjectBenchCraftingSlot(143, 36));
Expand Down

0 comments on commit f57712e

Please sign in to comment.