Skip to content

Commit

Permalink
More turtle game tests
Browse files Browse the repository at this point in the history
See #1682. Mostly trying to capture some behaviour I know has changed in
1.21, so we can verify it more easily.
  • Loading branch information
SquidDev committed Jan 12, 2025
1 parent f881c0c commit 5465770
Show file tree
Hide file tree
Showing 3 changed files with 327 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant
import dan200.computercraft.shared.peripheral.monitor.MonitorBlock
import dan200.computercraft.shared.peripheral.monitor.MonitorEdgeState
import dan200.computercraft.shared.turtle.apis.TurtleAPI
import dan200.computercraft.shared.turtle.core.TurtleCraftCommand
import dan200.computercraft.shared.util.WaterloggableHelpers
import dan200.computercraft.test.core.assertArrayEquals
import dan200.computercraft.test.core.computer.LuaTaskContext
Expand All @@ -46,8 +47,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType
import net.minecraft.world.level.block.state.properties.BlockStateProperties
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Assertions.*
import java.util.*
import java.util.concurrent.CopyOnWriteArrayList
import kotlin.time.Duration.Companion.milliseconds
Expand Down Expand Up @@ -163,6 +163,19 @@ class Turtle_Test {
}
}

/**
* Checks that turtles cannot use arbitrary blocks with `place()`.
*
* See [ComputerCraftTags.Blocks.TURTLE_CAN_USE].
*/
@GameTest
fun Place_does_not_use(helper: GameTestHelper) = helper.sequence {
thenOnComputer {
turtle.place(ObjectArguments()).await()
.assertArrayEquals(false, "Cannot place block here", message = "Failed to place item")
}
}

/**
* Checks that calling [net.minecraft.world.item.Item.use] will not place blocks too far away.
*
Expand Down Expand Up @@ -779,6 +792,43 @@ class Turtle_Test {
}
}

/**
* Test that turtles attempt crafts in all four corners.
*
* @see [#1918](https://github.com/cc-tweaked/CC-Tweaked/issues/1918)
*/
@GameTest
fun Craft_offset(helper: GameTestHelper) = helper.sequence {
for (offset in listOf(0, 1, 4, 5)) {
thenExecute {
val turtle = helper.getBlockEntity(BlockPos(2, 2, 2), ModRegistry.BlockEntities.TURTLE_NORMAL.get())

// Set up turtle inventory
turtle.clearContent()
turtle.setItem(offset + 0, ItemStack(Items.COBBLESTONE))
turtle.setItem(offset + 1, ItemStack(Items.COBBLESTONE))
turtle.setItem(offset + 2, ItemStack(Items.COBBLESTONE))
turtle.setItem(offset + 5, ItemStack(Items.STICK))
turtle.setItem(offset + 9, ItemStack(Items.STICK))

// Try to craft
assertTrue(TurtleCraftCommand(1).execute(turtle.access).isSuccess, "Crafting succeeded")

// And check item was crafted
assertThat(
"Inventory is as expected.",
turtle.contents,
contains(
isStack(Items.STONE_PICKAXE, 1), isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY),
isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY),
isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY),
isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY), isStack(ItemStack.EMPTY),
),
)
}
}
}

/**
* `turtle.equipLeft` equips a tool.
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5465770

Please sign in to comment.