Skip to content

Commit c1a649d

Browse files
committed
Fix crash with reusable items in a vertical pattern, Closes #42
1 parent 7fb761b commit c1a649d

2 files changed

Lines changed: 91 additions & 1 deletion

File tree

loader-common/src/main/java/org/cyclops/structuredcrafting/craft/WorldCraftingMatrix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public boolean handleRemainingItems(Level level, Direction inputSide, boolean si
226226
int i = r * 3 + c;
227227

228228
ItemStack originalStack = inventoryCrafting.getItem(i);
229-
ItemStack remainingStack = r >= top && r - top < craftInput.height() && c >= left && c - left < craftInput.width() ? remainingStacks.get((r - top) * craftInput.height() + c - left) : ItemStack.EMPTY;
229+
ItemStack remainingStack = r >= top && r - top < craftInput.height() && c >= left && c - left < craftInput.width() ? remainingStacks.get((r - top) * craftInput.width() + c - left) : ItemStack.EMPTY;
230230
if(originalStack != null && !originalStack.isEmpty()) {
231231
if (providers[i] != null) {
232232
// Consume one item from input

loader-common/src/main/java/org/cyclops/structuredcrafting/gametest/GameTestsCommon.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,96 @@ public void testCraftFromChestsToChestBannerCopy4(GameTestHelper helper) {
461461
});
462462
}
463463

464+
@GameTest(template = TEMPLATE_EMPTY)
465+
public void testCraftFromChestsToChestBannerCopy5(GameTestHelper helper) {
466+
helper.setBlock(POS.offset(2, 2, 2), RegistryEntries.BLOCK_STRUCTURED_CRAFTER.value()
467+
.defaultBlockState()
468+
.setValue(BlockStructuredCrafter.FACING, Direction.NORTH));
469+
470+
ItemStack patternBanner = new ItemStack(Items.WHITE_BANNER);
471+
patternBanner.set(DataComponents.BANNER_PATTERNS, new BannerPatternLayers.Builder()
472+
.add(helper.getLevel().registryAccess().asGetterLookup().get(Registries.BANNER_PATTERN, BannerPatterns.FLOWER).get(), DyeColor.YELLOW)
473+
.build());
474+
475+
// Define inputs
476+
setChestWithItem(helper, POS.offset(3, 3, 3), ItemStack.EMPTY);
477+
setChestWithItem(helper, POS.offset(2, 3, 3), new ItemStack(Items.WHITE_BANNER));
478+
setChestWithItem(helper, POS.offset(1, 3, 3), ItemStack.EMPTY);
479+
setChestWithItem(helper, POS.offset(3, 2, 3), ItemStack.EMPTY);
480+
setChestWithItem(helper, POS.offset(2, 2, 3), ItemStack.EMPTY);
481+
setChestWithItem(helper, POS.offset(1, 2, 3), ItemStack.EMPTY);
482+
setChestWithItem(helper, POS.offset(3, 1, 3), ItemStack.EMPTY);
483+
setChestWithItem(helper, POS.offset(2, 1, 3), patternBanner.copy());
484+
setChestWithItem(helper, POS.offset(1, 1, 3), ItemStack.EMPTY);
485+
486+
// Set output chest
487+
helper.setBlock(POS.offset(2, 2, 1), Blocks.CHEST);
488+
489+
// Activate crafter
490+
helper.setBlock(POS.offset(1, 2, 2), Blocks.REDSTONE_BLOCK);
491+
492+
helper.succeedWhen(() -> {
493+
// Result
494+
assertChestContains(helper, POS.offset(2, 2, 1), patternBanner);
495+
496+
// Inputs must be consumed
497+
assertChestEmpty(helper, POS.offset(3, 3, 3));
498+
assertChestEmpty(helper, POS.offset(2, 3, 3));
499+
assertChestEmpty(helper, POS.offset(1, 3, 3));
500+
assertChestEmpty(helper, POS.offset(3, 2, 3));
501+
assertChestEmpty(helper, POS.offset(2, 2, 3));
502+
assertChestEmpty(helper, POS.offset(1, 2, 3));
503+
assertChestEmpty(helper, POS.offset(3, 1, 3));
504+
assertChestContains(helper, POS.offset(2, 1, 3), patternBanner);
505+
assertChestEmpty(helper, POS.offset(1, 1, 3));
506+
});
507+
}
508+
509+
@GameTest(template = TEMPLATE_EMPTY)
510+
public void testCraftFromChestsToChestBannerCopy6(GameTestHelper helper) {
511+
helper.setBlock(POS.offset(2, 2, 2), RegistryEntries.BLOCK_STRUCTURED_CRAFTER.value()
512+
.defaultBlockState()
513+
.setValue(BlockStructuredCrafter.FACING, Direction.NORTH));
514+
515+
ItemStack patternBanner = new ItemStack(Items.WHITE_BANNER);
516+
patternBanner.set(DataComponents.BANNER_PATTERNS, new BannerPatternLayers.Builder()
517+
.add(helper.getLevel().registryAccess().asGetterLookup().get(Registries.BANNER_PATTERN, BannerPatterns.FLOWER).get(), DyeColor.YELLOW)
518+
.build());
519+
520+
// Define inputs
521+
setChestWithItem(helper, POS.offset(3, 3, 3), ItemStack.EMPTY);
522+
setChestWithItem(helper, POS.offset(2, 3, 3), patternBanner.copy());
523+
setChestWithItem(helper, POS.offset(1, 3, 3), ItemStack.EMPTY);
524+
setChestWithItem(helper, POS.offset(3, 2, 3), ItemStack.EMPTY);
525+
setChestWithItem(helper, POS.offset(2, 2, 3), ItemStack.EMPTY);
526+
setChestWithItem(helper, POS.offset(1, 2, 3), ItemStack.EMPTY);
527+
setChestWithItem(helper, POS.offset(3, 1, 3), ItemStack.EMPTY);
528+
setChestWithItem(helper, POS.offset(2, 1, 3), new ItemStack(Items.WHITE_BANNER));
529+
setChestWithItem(helper, POS.offset(1, 1, 3), ItemStack.EMPTY);
530+
531+
// Set output chest
532+
helper.setBlock(POS.offset(2, 2, 1), Blocks.CHEST);
533+
534+
// Activate crafter
535+
helper.setBlock(POS.offset(1, 2, 2), Blocks.REDSTONE_BLOCK);
536+
537+
helper.succeedWhen(() -> {
538+
// Result
539+
assertChestContains(helper, POS.offset(2, 2, 1), patternBanner);
540+
541+
// Inputs must be consumed
542+
assertChestEmpty(helper, POS.offset(3, 3, 3));
543+
assertChestContains(helper, POS.offset(2, 3, 3), patternBanner);
544+
assertChestEmpty(helper, POS.offset(1, 3, 3));
545+
assertChestEmpty(helper, POS.offset(3, 2, 3));
546+
assertChestEmpty(helper, POS.offset(2, 2, 3));
547+
assertChestEmpty(helper, POS.offset(1, 2, 3));
548+
assertChestEmpty(helper, POS.offset(3, 1, 3));
549+
assertChestEmpty(helper, POS.offset(2, 1, 3));
550+
assertChestEmpty(helper, POS.offset(1, 1, 3));
551+
});
552+
}
553+
464554
protected void setChestWithItem(GameTestHelper helper, BlockPos pos, ItemStack itemStack) {
465555
helper.setBlock(pos, Blocks.CHEST);
466556
ChestBlockEntity chest = helper.getBlockEntity(pos);

0 commit comments

Comments
 (0)