|
| 1 | +package me.desht.modularrouters.test.module; |
| 2 | + |
| 3 | +import me.desht.modularrouters.core.ModDataComponents; |
| 4 | +import me.desht.modularrouters.core.ModItems; |
| 5 | +import me.desht.modularrouters.logic.compiled.CompiledActivatorModule; |
| 6 | +import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.ActionType; |
| 7 | +import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.ActivatorSettings; |
| 8 | +import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.EntityMode; |
| 9 | +import me.desht.modularrouters.logic.compiled.CompiledActivatorModule.LookDirection; |
| 10 | +import me.desht.modularrouters.logic.settings.RelativeDirection; |
| 11 | +import me.desht.modularrouters.test.RouterTestHelper; |
| 12 | +import me.desht.modularrouters.test.RouterTestHelper.ModuleSettingsBuilder; |
| 13 | +import net.minecraft.core.BlockPos; |
| 14 | +import net.minecraft.core.Direction; |
| 15 | +import net.minecraft.gametest.framework.GameTest; |
| 16 | +import net.minecraft.world.entity.EntityType; |
| 17 | +import net.minecraft.world.item.ItemStack; |
| 18 | +import net.minecraft.world.item.Items; |
| 19 | +import net.minecraft.world.level.block.Blocks; |
| 20 | +import net.minecraft.world.level.block.LeverBlock; |
| 21 | +import net.neoforged.testframework.annotation.TestHolder; |
| 22 | +import net.neoforged.testframework.gametest.EmptyTemplate; |
| 23 | + |
| 24 | +public class ActivatorModuleTest { |
| 25 | + @GameTest |
| 26 | + @TestHolder |
| 27 | + @EmptyTemplate(floor = true) |
| 28 | + static void activatorTestBlock(final RouterTestHelper helper) { |
| 29 | + var router = helper.placeRouter(0, 2, 1, Direction.EAST); |
| 30 | + helper.setBlock(2, 2, 1, Blocks.LEVER); |
| 31 | + |
| 32 | + ItemStack activator = ModItems.ACTIVATOR_MODULE.toStack(); |
| 33 | + activator.set(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettingsBuilder.create().facing(RelativeDirection.FRONT).build()); |
| 34 | + router.addModule(activator); |
| 35 | + |
| 36 | + helper.startSequence() |
| 37 | + .thenIdle(router.routerTicks(1)) |
| 38 | + .thenExecute(() -> helper.assertBlockProperty(new BlockPos(2, 2, 1), LeverBlock.POWERED, true)) |
| 39 | + .thenSucceed(); |
| 40 | + } |
| 41 | + |
| 42 | + @GameTest |
| 43 | + @TestHolder |
| 44 | + @EmptyTemplate(floor = true) |
| 45 | + static void activatorTestItem(final RouterTestHelper helper) { |
| 46 | + var router = helper.placeRouter(1, 2, 1, Direction.EAST); |
| 47 | + helper.setBlock(2, 2, 1, Blocks.AIR); |
| 48 | + |
| 49 | + ItemStack activator = ModItems.ACTIVATOR_MODULE.toStack(); |
| 50 | + activator.set(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettingsBuilder.create().facing(RelativeDirection.FRONT).build()); |
| 51 | + activator.set(ModDataComponents.ACTIVATOR_SETTINGS, new ActivatorSettings( |
| 52 | + ActionType.ITEM_OR_BLOCK, LookDirection.BELOW, EntityMode.NEAREST, false) |
| 53 | + ); |
| 54 | + router.addModule(activator); |
| 55 | + router.insertBuffer(Items.FLINT_AND_STEEL.getDefaultInstance()); |
| 56 | + |
| 57 | + helper.startSequence() |
| 58 | + .thenIdle(router.routerTicks(1)) |
| 59 | + .thenExecute(() -> helper.assertBlockPresent(Blocks.FIRE, 2,2 , 1)) |
| 60 | + .thenSucceed(); |
| 61 | + } |
| 62 | + |
| 63 | + @GameTest |
| 64 | + @TestHolder |
| 65 | + @EmptyTemplate(floor = true) |
| 66 | + static void activatorTestEntity(final RouterTestHelper helper) { |
| 67 | + var router = helper.placeRouter(1, 2, 1, Direction.EAST); |
| 68 | + helper.spawn(EntityType.COW, 2, 2, 1); |
| 69 | + |
| 70 | + ItemStack activator = ModItems.ACTIVATOR_MODULE.toStack(); |
| 71 | + activator.set(ModDataComponents.COMMON_MODULE_SETTINGS, ModuleSettingsBuilder.create().facing(RelativeDirection.FRONT).build()); |
| 72 | + activator.set(ModDataComponents.ACTIVATOR_SETTINGS, new ActivatorSettings( |
| 73 | + ActionType.USE_ITEM_ON_ENTITY, LookDirection.LEVEL, EntityMode.NEAREST, false) |
| 74 | + ); |
| 75 | + router.addModule(activator); |
| 76 | + router.insertBuffer(Items.BUCKET.getDefaultInstance()); |
| 77 | + |
| 78 | + helper.startSequence() |
| 79 | + .thenIdle(router.routerTicks(1)) |
| 80 | + .thenExecute(() -> router.assertBuffer(Items.MILK_BUCKET, 1)) |
| 81 | + // 4 buckets in router; 3 empty buckets should stay, 1 milk bucket dropped |
| 82 | + .thenExecute(() -> router.setBuffer(new ItemStack(Items.BUCKET, 4))) |
| 83 | + .thenIdle(router.routerTicks(1)) |
| 84 | + .thenExecute(() -> router.assertBuffer(Items.BUCKET, 3)) |
| 85 | + .thenExecute(() -> helper.assertItemEntityCountIs(Items.MILK_BUCKET, new BlockPos(2, 2, 1), 1.0, 1)) |
| 86 | + .thenSucceed(); |
| 87 | + |
| 88 | + } |
| 89 | +} |
0 commit comments