mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-03-17 17:00:01 +01:00
Fixed spellbook crafting slot weightings not matching the documented behaviour
This commit is contained in:
parent
26063e98a2
commit
a73d0cb3ea
9 changed files with 89 additions and 86 deletions
|
@ -70,9 +70,9 @@ public class SpellbookScreenHandler extends ScreenHandler {
|
||||||
inventory = inv;
|
inventory = inv;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
List<int[]> grid = new ArrayList<>();
|
List<HexagonalCraftingGrid.Slot> grid = new ArrayList<>();
|
||||||
List<int[]> gemPos = new ArrayList<>();
|
List<HexagonalCraftingGrid.Slot> gemPos = new ArrayList<>();
|
||||||
SpellbookCraftingGrid.createGrid(grid, gemPos);
|
HexagonalCraftingGrid.create(34, 65, 3, grid, gemPos);
|
||||||
|
|
||||||
MAX_INGREDIENTS = grid.size();
|
MAX_INGREDIENTS = grid.size();
|
||||||
GEM_SLOT_INDEX = MAX_INGREDIENTS;
|
GEM_SLOT_INDEX = MAX_INGREDIENTS;
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.minelittlepony.unicopia.container.inventory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface HexagonalCraftingGrid {
|
||||||
|
int SPACING = 23;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a hexagonal crafting grid.
|
||||||
|
* @param grid Output for normal slot positions.
|
||||||
|
* @param gemPos Output for the gem slot position.
|
||||||
|
*/
|
||||||
|
static void create(int top, int left, int rings, List<Slot> grid, List<Slot> gemPos) {
|
||||||
|
rings++;
|
||||||
|
|
||||||
|
final int ROWS = (rings * 2) - 1;
|
||||||
|
final int INFLECTION_POINT = ROWS / 2;
|
||||||
|
|
||||||
|
int cols = rings;
|
||||||
|
|
||||||
|
for (int y = 0; y < ROWS; y++) {
|
||||||
|
for (int x = 0; x < cols; x++) {
|
||||||
|
(y == 3 && x == 3 ? gemPos : grid).add(new Slot(
|
||||||
|
left + (x * SPACING),
|
||||||
|
top,
|
||||||
|
getWeight(x, y, cols, ROWS)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
int change = y >= INFLECTION_POINT ? -1 : 1;
|
||||||
|
|
||||||
|
top += SPACING * 0.9;
|
||||||
|
left -= (SPACING / 2) * change;
|
||||||
|
cols += change;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static float getWeight(int x, int y, int cols, int rows) {
|
||||||
|
if (y == 3 && x == 3) {
|
||||||
|
return SpellbookSlot.CENTER_FACTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == 0 || y == (rows - 1) || x == 0 || x == (cols - 1)) {
|
||||||
|
return SpellbookSlot.FAR_FACTOR;
|
||||||
|
}
|
||||||
|
if (y == 1 || y == (rows - 2) || x == 1 || x == (cols - 2)) {
|
||||||
|
return SpellbookSlot.MIDDLE_FACTOR;
|
||||||
|
}
|
||||||
|
return SpellbookSlot.NEAR_FACTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
record Slot (
|
||||||
|
int left,
|
||||||
|
int top,
|
||||||
|
float weight
|
||||||
|
) {}
|
||||||
|
}
|
|
@ -8,12 +8,12 @@ import net.minecraft.screen.slot.Slot;
|
||||||
|
|
||||||
public class IngredientSlot extends Slot implements SpellbookSlot {
|
public class IngredientSlot extends Slot implements SpellbookSlot {
|
||||||
private final SpellbookScreenHandler handler;
|
private final SpellbookScreenHandler handler;
|
||||||
private final int ring;
|
private final float weight;
|
||||||
|
|
||||||
public IngredientSlot(SpellbookScreenHandler handler, Inventory inventory, int index, int[] params) {
|
public IngredientSlot(SpellbookScreenHandler handler, Inventory inventory, int index, HexagonalCraftingGrid.Slot params) {
|
||||||
super(inventory, index, params[0], params[1]);
|
super(inventory, index, params.left(), params.top());
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
ring = params[2];
|
weight = params.weight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,8 +27,8 @@ public class IngredientSlot extends Slot implements SpellbookSlot {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRing() {
|
public float getWeight() {
|
||||||
return ring;
|
return weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,12 +7,12 @@ import net.minecraft.screen.slot.Slot;
|
||||||
|
|
||||||
public class InputSlot extends Slot implements SpellbookSlot {
|
public class InputSlot extends Slot implements SpellbookSlot {
|
||||||
private final SpellbookScreenHandler handler;
|
private final SpellbookScreenHandler handler;
|
||||||
private final int ring;
|
private final float weight;
|
||||||
|
|
||||||
public InputSlot(SpellbookScreenHandler handler, Inventory inventory, int index, int[] params) {
|
public InputSlot(SpellbookScreenHandler handler, Inventory inventory, int index, HexagonalCraftingGrid.Slot params) {
|
||||||
super(inventory, index, params[0], params[1]);
|
super(inventory, index, params.left(), params.top());
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.ring = params[2];
|
this.weight = params.weight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,8 +21,8 @@ public class InputSlot extends Slot implements SpellbookSlot {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRing() {
|
public float getWeight() {
|
||||||
return ring;
|
return weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,11 +13,6 @@ public class InventorySlot extends Slot implements SpellbookSlot {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRing() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return handler.canShowSlots.test(SlotType.INVENTORY);
|
return handler.canShowSlots.test(SlotType.INVENTORY);
|
||||||
|
|
|
@ -19,14 +19,14 @@ public class OutputSlot extends CraftingResultSlot implements SpellbookSlot {
|
||||||
private final PlayerEntity player;
|
private final PlayerEntity player;
|
||||||
private final SpellbookInventory input;
|
private final SpellbookInventory input;
|
||||||
|
|
||||||
private final int ring;
|
private final float weight;
|
||||||
|
|
||||||
public OutputSlot(SpellbookScreenHandler spellbookScreenHandler, PlayerEntity player, SpellbookInventory input, Inventory inventory, int index, int[] params) {
|
public OutputSlot(SpellbookScreenHandler spellbookScreenHandler, PlayerEntity player, SpellbookInventory input, Inventory inventory, int index, HexagonalCraftingGrid.Slot params) {
|
||||||
super(player, input, inventory, index, params[0], params[1]);
|
super(player, input, inventory, index, params.left(), params.top());
|
||||||
handler = spellbookScreenHandler;
|
handler = spellbookScreenHandler;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.ring = params[2];
|
this.weight = params.weight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,8 +40,8 @@ public class OutputSlot extends CraftingResultSlot implements SpellbookSlot {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRing() {
|
public float getWeight() {
|
||||||
return ring;
|
return weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
package com.minelittlepony.unicopia.container.inventory;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface SpellbookCraftingGrid {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a hexagonal crafting grid.
|
|
||||||
* @param grid Output for normal slot positions.
|
|
||||||
* @param gemPos Output for the gem slot position.
|
|
||||||
*/
|
|
||||||
static void createGrid(List<int[]> grid, List<int[]> gemPos) {
|
|
||||||
int cols = 4;
|
|
||||||
int spacing = 23;
|
|
||||||
|
|
||||||
int top = 34;
|
|
||||||
int left = 65;
|
|
||||||
|
|
||||||
for (int row = 0; row < 7; row++) {
|
|
||||||
for (int i = 0; i < cols; i++) {
|
|
||||||
|
|
||||||
int ring = 3;
|
|
||||||
if (row == 0 || row == 6) {
|
|
||||||
ring = 1;
|
|
||||||
} else if ((row == 1 || row == 5) && i > 0 && i < cols - 1) {
|
|
||||||
ring = 2;
|
|
||||||
} else {
|
|
||||||
if (i == 0 || i == cols - 1) {
|
|
||||||
ring = 1;
|
|
||||||
} else if (i == 1 || i == cols - 2) {
|
|
||||||
ring = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(row == 3 && i == 3 ? gemPos : grid).add(new int[] {
|
|
||||||
left + (i * spacing),
|
|
||||||
top,
|
|
||||||
row == 3 && i == 3 ? 4 : ring
|
|
||||||
});
|
|
||||||
}
|
|
||||||
top += spacing * 0.9;
|
|
||||||
left -= (spacing / 2) * (row > 2 ? -1 : 1);
|
|
||||||
cols += row > 2 ? -1 : 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -29,24 +29,15 @@ public class SpellbookInventory extends CraftingInventory {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRing(int slot) {
|
public float getFactor(int slot) {
|
||||||
Slot s = handler.slots.get(slot);
|
Slot s = handler.slots.get(slot);
|
||||||
return s instanceof SpellbookSlot ? ((SpellbookSlot)s).getRing() : 0;
|
return s instanceof SpellbookSlot ? ((SpellbookSlot)s).getWeight() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpellTraits getTraits() {
|
public SpellTraits getTraits() {
|
||||||
return SpellTraits.union(InventoryUtil.slots(this)
|
return SpellTraits.union(InventoryUtil.slots(this)
|
||||||
.map(slot -> SpellTraits.of(getStack(slot)).multiply(getRingFactor(getRing(slot))))
|
.map(slot -> SpellTraits.of(getStack(slot)).multiply(getFactor(slot)))
|
||||||
.toArray(SpellTraits[]::new)
|
.toArray(SpellTraits[]::new)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getRingFactor(int ring) {
|
|
||||||
switch (ring) {
|
|
||||||
case 1: return 1;
|
|
||||||
case 2: return 0.6F;
|
|
||||||
case 3: return 0.3F;
|
|
||||||
default: return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,5 +1,12 @@
|
||||||
package com.minelittlepony.unicopia.container.inventory;
|
package com.minelittlepony.unicopia.container.inventory;
|
||||||
|
|
||||||
public interface SpellbookSlot {
|
public interface SpellbookSlot {
|
||||||
int getRing();
|
float CENTER_FACTOR = 0;
|
||||||
|
float NEAR_FACTOR = 1;
|
||||||
|
float MIDDLE_FACTOR = 0.6F;
|
||||||
|
float FAR_FACTOR = 0.3F;
|
||||||
|
|
||||||
|
default float getWeight() {
|
||||||
|
return CENTER_FACTOR;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue