Skip to content

Commit

Permalink
Add basic autocrafting dropper test to prevent future crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
altrisi committed Aug 23, 2024
1 parent fa4eec7 commit ae742a9
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/gametest/java/carpetextra/test/DispenserWithBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void before(ServerWorld world) {
CarpetExtraSettings.blazeMeal = true;
CarpetExtraSettings.renewableEndstone = true;
CarpetExtraSettings.renewableNetherrack = true;
CarpetExtraSettings.autoCraftingDropper = true; // TODO separate, further testing for this feature
}

@AfterBatch(batchId = BATCH)
Expand All @@ -62,6 +63,7 @@ public void after(ServerWorld world) {
CarpetExtraSettings.blazeMeal = false;
CarpetExtraSettings.renewableEndstone = false;
CarpetExtraSettings.renewableNetherrack = false;
CarpetExtraSettings.autoCraftingDropper = false;
}

@GameTest(templateName = STRUCTURE, batchId = BATCH)
Expand Down Expand Up @@ -299,14 +301,47 @@ private void cartTest(TestContext ctx, Item item, EntityType<?> entity, Runnable
ctx.spawnEntity(EntityType.MINECART, lapis.up());

ctx.pushButton(button);
ctx.addFinalTaskWithDuration(4, () -> {
ctx.addFinalTaskWithDuration(DISPENSER_DELAY, () -> {
ctx.expectEntityAt(entity, lapis.up());
ctx.dontExpectEntity(EntityType.MINECART);
ctx.dontExpectEntity(EntityType.ITEM);
runAll(extras);
});
}

// very basic autocrafting test, for now just to catch simple crashes or malfunctioning stuff
@GameTest(templateName = STRUCTURE, batchId = BATCH)
public void craftCake(TestContext ctx) {
Item[] recipe = new Item[] {
Items.MILK_BUCKET, Items.MILK_BUCKET, Items.MILK_BUCKET,
Items.SUGAR, Items.EGG, Items.SUGAR,
Items.WHEAT, Items.WHEAT, Items.WHEAT
};
ctx.setBlockState(dispenser, Blocks.DROPPER.getStateWithProperties(ctx.getBlockState(dispenser)));
ctx.setBlockState(lapis.up(), Blocks.CRAFTING_TABLE);
for (int i = 0; i < 9; i++) {
ctx.<DispenserBlockEntity>getBlockEntity(dispenser).setStack(i, recipe[i].getDefaultStack());
}
ctx.pushButton(button);

ctx.addFinalTaskWithDuration(DISPENSER_DELAY, () -> {
ctx.expectItem(Items.CAKE);
for (Item item : recipe) ctx.dontExpectItem(item);
for (int i = 0; i < 3; i++) {
int finalI = i;
ctx.<DispenserBlockEntity>checkBlockEntity(dispenser,
disp -> disp.getStack(finalI).getItem() == Items.BUCKET,
() -> "Must have buckets remaining in dispenser");
}
for (int i = 3; i < 9; i++) {
int finalI = i;
ctx.<DispenserBlockEntity>checkBlockEntity(dispenser,
disp -> disp.getStack(finalI).isEmpty(),
() -> "Must not have anything but the first 3 buckets in dispenser");
}
});
}

// Util
private void putInDispenser(TestContext ctx, ItemStack item) {
ctx.<DispenserBlockEntity>getBlockEntity(dispenser).addToFirstFreeSlot(item);
Expand Down

0 comments on commit ae742a9

Please sign in to comment.