-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweaked RouterTestHelper a bit
- Loading branch information
Showing
4 changed files
with
222 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/test/java/me/desht/modularrouters/test/module/ActivatorModuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package me.desht.modularrouters.test.module; | ||
|
||
import me.desht.modularrouters.core.ModDataComponents; | ||
import me.desht.modularrouters.core.ModItems; | ||
import me.desht.modularrouters.logic.compiled.CompiledActivatorModule; | ||
import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.ActionType; | ||
import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.ActivatorSettings; | ||
import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.EntityMode; | ||
import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.LookDirection; | ||
import me.desht.modularrouters.logic.settings.RelativeDirection; | ||
import me.desht.modularrouters.test.RouterTestHelper; | ||
import me.desht.modularrouters.test.RouterTestHelper.ModuleSettingsBuilder; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.LeverBlock; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
import net.neoforged.testframework.gametest.EmptyTemplate; | ||
|
||
public class ActivatorModuleTest { | ||
@GameTest | ||
@TestHolder | ||
@EmptyTemplate(floor = true) | ||
static void activatorTestBlock(final RouterTestHelper helper) { | ||
var router = helper.placeRouter(0, 2, 1, Direction.EAST); | ||
helper.setBlock(2, 2, 1, Blocks.LEVER); | ||
|
||
ItemStack activator = ModItems.ACTIVATOR_MODULE.toStack(); | ||
activator.set(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettingsBuilder.create().facing(RelativeDirection.FRONT).build()); | ||
router.addModule(activator); | ||
|
||
helper.startSequence() | ||
.thenIdle(router.routerTicks(1)) | ||
.thenExecute(() -> helper.assertBlockProperty(new BlockPos(2, 2, 1), LeverBlock.POWERED, true)) | ||
.thenSucceed(); | ||
} | ||
|
||
@GameTest | ||
@TestHolder | ||
@EmptyTemplate(floor = true) | ||
static void activatorTestItem(final RouterTestHelper helper) { | ||
var router = helper.placeRouter(1, 2, 1, Direction.EAST); | ||
helper.setBlock(2, 2, 1, Blocks.AIR); | ||
|
||
ItemStack activator = ModItems.ACTIVATOR_MODULE.toStack(); | ||
activator.set(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettingsBuilder.create().facing(RelativeDirection.FRONT).build()); | ||
activator.set(ModDataComponents.ACTIVATOR_SETTINGS, new ActivatorSettings( | ||
ActionType.ITEM_OR_BLOCK, LookDirection.BELOW, EntityMode.NEAREST, false) | ||
); | ||
router.addModule(activator); | ||
router.insertBuffer(Items.FLINT_AND_STEEL.getDefaultInstance()); | ||
|
||
helper.startSequence() | ||
.thenIdle(router.routerTicks(1)) | ||
.thenExecute(() -> helper.assertBlockPresent(Blocks.FIRE, 2,2 , 1)) | ||
.thenSucceed(); | ||
} | ||
|
||
@GameTest | ||
@TestHolder | ||
@EmptyTemplate(floor = true) | ||
static void activatorTestEntity(final RouterTestHelper helper) { | ||
var router = helper.placeRouter(1, 2, 1, Direction.EAST); | ||
helper.spawn(EntityType.COW, 2, 2, 1); | ||
|
||
ItemStack activator = ModItems.ACTIVATOR_MODULE.toStack(); | ||
activator.set(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettingsBuilder.create().facing(RelativeDirection.FRONT).build()); | ||
activator.set(ModDataComponents.ACTIVATOR_SETTINGS, new ActivatorSettings( | ||
ActionType.USE_ITEM_ON_ENTITY, LookDirection.LEVEL, EntityMode.NEAREST, false) | ||
); | ||
router.addModule(activator); | ||
router.insertBuffer(Items.BUCKET.getDefaultInstance()); | ||
|
||
helper.startSequence() | ||
.thenIdle(router.routerTicks(1)) | ||
.thenExecute(() -> router.assertBuffer(Items.MILK_BUCKET, 1)) | ||
// 4 buckets in router; 3 empty buckets should stay, 1 milk bucket dropped | ||
.thenExecute(() -> router.setBuffer(new ItemStack(Items.BUCKET, 4))) | ||
.thenIdle(router.routerTicks(1)) | ||
.thenExecute(() -> router.assertBuffer(Items.BUCKET, 3)) | ||
.thenExecute(() -> helper.assertItemEntityCountIs(Items.MILK_BUCKET, new BlockPos(2, 2, 1), 1.0, 1)) | ||
.thenSucceed(); | ||
|
||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/me/desht/modularrouters/test/module/DropperModuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package me.desht.modularrouters.test.module; | ||
|
||
import me.desht.modularrouters.core.ModItems; | ||
import me.desht.modularrouters.logic.settings.RelativeDirection; | ||
import me.desht.modularrouters.test.RouterTestHelper; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
import net.neoforged.testframework.gametest.EmptyTemplate; | ||
|
||
public class DropperModuleTest { | ||
@GameTest | ||
@TestHolder | ||
@EmptyTemplate(floor = true) | ||
static void testDropperModule(final RouterTestHelper helper) { | ||
var router = helper.placeRouter(1, 1, 1); | ||
|
||
router.addDirectionalModule(ModItems.DROPPER_MODULE, RelativeDirection.UP); | ||
|
||
helper.startSequence() | ||
.thenExecute(() -> router.insertBuffer(new ItemStack(Items.DIAMOND))) | ||
.thenIdle(router.routerTicks(1)) | ||
.thenExecute(router::assertBufferEmpty) | ||
.thenExecute(() -> helper.assertItemEntityPresent(Items.DIAMOND, new BlockPos(1, 2, 1), 0.0)) | ||
.thenSucceed(); | ||
} | ||
|
||
@GameTest | ||
@TestHolder | ||
@EmptyTemplate(floor = true) | ||
static void testDropperModuleStacked(final RouterTestHelper helper) { | ||
var router = helper.placeRouter(1, 1, 1); | ||
|
||
router.addDirectionalModule(ModItems.DROPPER_MODULE, RelativeDirection.FRONT); // effectively north | ||
router.addUpgrade(ModItems.STACK_UPGRADE.toStack(5)); // 32 items at a time | ||
|
||
helper.startSequence() | ||
.thenExecute(() -> router.insertBuffer(new ItemStack(Items.DIAMOND, 64))) | ||
.thenIdle(router.routerTicks(1)) | ||
.thenExecute(() -> router.assertBuffer(Items.DIAMOND, 32)) | ||
.thenExecute(() -> helper.assertItemEntityCountIs(Items.DIAMOND, new BlockPos(1, 1, 0), 0.0, 32)) | ||
.thenSucceed(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/me/desht/modularrouters/test/module/FilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package me.desht.modularrouters.test.module; | ||
|
||
import me.desht.modularrouters.core.ModDataComponents; | ||
import me.desht.modularrouters.core.ModItems; | ||
import me.desht.modularrouters.logic.settings.*; | ||
import me.desht.modularrouters.test.RouterTestHelper; | ||
import me.desht.modularrouters.test.RouterTestHelper.ModuleSettingsBuilder; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.item.component.ItemContainerContents; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
import net.neoforged.testframework.gametest.EmptyTemplate; | ||
|
||
import java.util.List; | ||
|
||
public class FilterTest { | ||
@GameTest | ||
@TestHolder | ||
@EmptyTemplate | ||
static void simpleFilterTest(final RouterTestHelper helper) { | ||
var router = helper.placeRouter(1, 1, 1); | ||
|
||
var topChest = helper.placeChest(1, 2, 1); // above router | ||
var northChest = helper.placeChest(1, 1, 0); // north of router | ||
|
||
// first module blacklists cobblestone | ||
ItemStack sender1 = ModItems.SENDER_MODULE_1.toStack(); | ||
sender1.set(ModDataComponents.FILTER, ItemContainerContents.fromItems(List.of(Items.COBBLESTONE.getDefaultInstance()))); | ||
sender1.set(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettingsBuilder.create().facing(RelativeDirection.UP).build()); | ||
router.router().getModules().insertItem(0, sender1, false); | ||
|
||
// second module has empty blacklist | ||
ItemStack sender2 = ModItems.SENDER_MODULE_1.toStack(); | ||
sender2.set(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettingsBuilder.create().facing(RelativeDirection.FRONT).build()); | ||
router.router().getModules().insertItem(1, sender2, false); | ||
|
||
router.insertBuffer(new ItemStack(Items.COBBLESTONE, 2)); | ||
|
||
helper.startSequence() | ||
.thenIdle(router.routerTicks(2)) | ||
.thenExecute(router::assertBufferEmpty) | ||
.thenExecute(() -> helper.assertValueEqual(topChest.countItem(Items.COBBLESTONE), 0, "top chest cobblestone")) | ||
.thenExecute(() -> helper.assertValueEqual(northChest.countItem(Items.COBBLESTONE), 2, "north chest cobblestone")) | ||
.thenExecute(() -> router.insertBuffer(new ItemStack(Items.IRON_INGOT, 2))) | ||
.thenIdle(router.routerTicks(2)) | ||
.thenExecute(() -> helper.assertValueEqual(topChest.countItem(Items.IRON_INGOT), 1, "top chest iron")) | ||
.thenExecute(() -> helper.assertValueEqual(topChest.countItem(Items.IRON_INGOT), 1, "north chest iron")) | ||
.thenSucceed(); | ||
} | ||
} |