Skip to content

Commit

Permalink
Fix GameTestHelper#forEveryBlockInStructure including blocks that a…
Browse files Browse the repository at this point in the history
…re not in the structure (neoforged#401)
  • Loading branch information
pupnewfster authored Dec 18, 2023
1 parent ae90c8a commit 97f3373
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions patches/net/minecraft/gametest/framework/GameTestHelper.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/net/minecraft/gametest/framework/GameTestHelper.java
+++ b/net/minecraft/gametest/framework/GameTestHelper.java
@@ -836,7 +_,8 @@

public void forEveryBlockInStructure(Consumer<BlockPos> p_177293_) {
AABB aabb = this.getRelativeBounds();
- BlockPos.MutableBlockPos.betweenClosedStream(aabb.move(0.0, 1.0, 0.0)).forEach(p_177293_);
+ // Neo: Shrink AABB by one as an aabb surrounding two blocks is increased by one compared to the actual positions
+ BlockPos.MutableBlockPos.betweenClosedStream(aabb.contract(1.0, 1.0, 1.0)).forEach(p_177293_);
}

public void onEachTick(Runnable p_177424_) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.debug.structure;

import net.minecraft.gametest.framework.GameTest;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.testframework.DynamicTest;
import net.neoforged.testframework.annotation.ForEachTest;
import net.neoforged.testframework.annotation.TestHolder;
import net.neoforged.testframework.gametest.StructureTemplateBuilder;

@ForEachTest(groups = StructureTests.GROUP)
public class StructureTests {
public static final String GROUP = "structure";

@GameTest
@TestHolder(description = "Tests that the structure bounds for use in Game Tests is correct")
static void everyBlockInStructure(final DynamicTest test) {
test.registerGameTestTemplate(() -> StructureTemplateBuilder.withSize(3, 3, 3)
.fill(0, 0, 0, 2, 2, 2, Blocks.DIAMOND_BLOCK));

test.onGameTest(helper -> helper.startSequence()
.thenWaitUntil(0, () -> helper.forEveryBlockInStructure(pos -> helper.assertBlockPresent(Blocks.DIAMOND_BLOCK, pos)))
.thenExecute(test::pass)
.thenSucceed());
}
}

0 comments on commit 97f3373

Please sign in to comment.