mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-08 15:10:05 +00:00
Search for items in the whole gametest structure
This fixes some flakiness where items get thrown outside a 1 block radius.
This commit is contained in:
parent
b89e2615db
commit
3299d0e72a
@ -123,11 +123,10 @@ class Computer_Test {
|
||||
@GameTest
|
||||
fun Drops_on_explosion(context: GameTestHelper) = context.sequence {
|
||||
thenExecute {
|
||||
val pos = BlockPos(2, 2, 2)
|
||||
val explosionPos = Vec3.atCenterOf(context.absolutePos(pos))
|
||||
val explosionPos = Vec3.atCenterOf(context.absolutePos(BlockPos(2, 2, 2)))
|
||||
context.level.explode(null, explosionPos.x, explosionPos.y, explosionPos.z, 2.0f, Level.ExplosionInteraction.TNT)
|
||||
|
||||
context.assertItemEntityPresent(ModRegistry.Items.COMPUTER_NORMAL.get(), pos, 1.0)
|
||||
context.assertItemEntityCountIs(ModRegistry.Items.COMPUTER_NORMAL.get(), 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -703,8 +703,8 @@ class Turtle_Test {
|
||||
thenOnComputer { turtle.dig(Optional.empty()) }
|
||||
thenIdle(2)
|
||||
thenExecute {
|
||||
context.assertItemEntityCountIs(ModRegistry.Items.TURTLE_NORMAL.get(), BlockPos(2, 2, 2), 1.0, 1)
|
||||
context.assertItemEntityCountIs(Items.BONE_BLOCK, BlockPos(2, 2, 2), 1.0, 65)
|
||||
context.assertItemEntityCountIs(ModRegistry.Items.TURTLE_NORMAL.get(), 1)
|
||||
context.assertItemEntityCountIs(Items.BONE_BLOCK, 65)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import net.minecraft.world.Container
|
||||
import net.minecraft.world.InteractionHand
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.entity.EntityType
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.context.UseOnContext
|
||||
import net.minecraft.world.level.block.Blocks
|
||||
@ -252,6 +253,16 @@ fun GameTestHelper.assertExactlyItems(vararg expected: ItemStack, message: Strin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to [GameTestHelper.assertItemEntityCountIs], but searching anywhere in the structure bounds.
|
||||
*/
|
||||
fun GameTestHelper.assertItemEntityCountIs(expected: Item, count: Int) {
|
||||
val actualCount = getEntities(EntityType.ITEM).sumOf { if (it.item.`is`(expected)) it.item.count else 0 }
|
||||
if (actualCount != count) {
|
||||
throw GameTestAssertException("Expected $count ${expected.description.string} items to exist (found $actualCount)")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getName(type: BlockEntityType<*>): ResourceLocation = RegistryWrappers.BLOCK_ENTITY_TYPES.getKey(type)!!
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user