Skip to content

Commit 83ad847

Browse files
committed
Add support for rotated recipes
1 parent 80b7507 commit 83ad847

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

src/main/java/org/cyclops/structuredcrafting/craft/WorldCraftingMatrix.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,35 @@ public boolean craft() {
8686

8787
BlockPos[] positions = new BlockPos[9];
8888
IItemStackProvider[] providers = new IItemStackProvider[9];
89-
// Set crafting grid
90-
for(int i = -1; i < 2; i++) {
91-
for(int j = -1; j < 2; j++) {
92-
int arrayIndex = (j + 1) * 3 + (i + 1);
93-
BlockPos pos = addInAxis(centerPos, axis, i, j);
94-
Pair<ItemStack, IItemStackProvider> result = determineItemStackProviderForInput(world, pos, inputSide);
95-
ItemStack itemStack = result != null ? result.getLeft() : null;
96-
if(itemStack != null) {
97-
itemStack = itemStack.copy();
98-
itemStack.stackSize = 1;
89+
ItemStack itemStack = null;
90+
for(int k = 0; k < 2; k++) {
91+
// Set crafting grid
92+
if(itemStack == null) {
93+
for (int i = -1; i < 2; i++) {
94+
for (int j = -1; j < 2; j++) {
95+
int arrayIndex = (j + 1) * 3 + (i + 1);
96+
BlockPos pos = addInAxis(centerPos, axis, i, j);
97+
Pair<ItemStack, IItemStackProvider> result = determineItemStackProviderForInput(world, pos, inputSide);
98+
ItemStack itemStackInput = result != null ? result.getLeft() : null;
99+
if (itemStackInput != null) {
100+
itemStackInput = itemStackInput.copy();
101+
itemStackInput.stackSize = 1;
102+
}
103+
// This makes sure we can also accept recipes which are rotated, mirroring is already supported by Vanilla.
104+
if (k == 0) {
105+
INVENTORY_CRAFTING.setItemStack(i + 1, j + 1, itemStackInput);
106+
} else {
107+
INVENTORY_CRAFTING.setItemStack(j + 1, i + 1, itemStackInput);
108+
}
109+
positions[arrayIndex] = pos;
110+
providers[arrayIndex] = result != null ? result.getRight() : null;
111+
}
99112
}
100-
INVENTORY_CRAFTING.setItemStack(i + 1, j + 1, itemStack);
101-
positions[arrayIndex] = pos;
102-
providers[arrayIndex] = result != null ? result.getRight() : null;
113+
itemStack = CraftingManager.getInstance().findMatchingRecipe(INVENTORY_CRAFTING, world);
103114
}
104115
}
105116

106117
// Determine output
107-
ItemStack itemStack = CraftingManager.getInstance().findMatchingRecipe(INVENTORY_CRAFTING, world);
108118
if(itemStack != null && addItemStackForOutput(world, targetPos, targetSide, outputProviders, itemStack)) {
109119
// Handle remaining container items: place blocks and drop items
110120
ItemStack[] remainingStacks = CraftingManager.getInstance().func_180303_b(INVENTORY_CRAFTING, world);

0 commit comments

Comments
 (0)