|
1 | 1 | package io.github.mooy1.infinitylib.machines; |
2 | 2 |
|
3 | 3 | import org.bukkit.Material; |
4 | | -import org.bukkit.block.Block; |
5 | 4 | import org.bukkit.inventory.ItemStack; |
6 | 5 | import org.junit.jupiter.api.AfterAll; |
7 | 6 | import org.junit.jupiter.api.BeforeAll; |
|
11 | 10 | import org.junit.jupiter.api.TestMethodOrder; |
12 | 11 |
|
13 | 12 | import be.seeseemelk.mockbukkit.MockBukkit; |
14 | | -import be.seeseemelk.mockbukkit.ServerMock; |
15 | 13 | import io.github.mooy1.infinitylib.core.MockAddon; |
16 | 14 | import io.github.mooy1.infinitylib.groups.SubGroup; |
17 | 15 | import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; |
18 | 16 | import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; |
19 | 17 | import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; |
20 | 18 | import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; |
21 | 19 | import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; |
22 | | -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; |
23 | | -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; |
24 | 20 |
|
25 | 21 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
26 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; |
27 | | -import static org.junit.jupiter.api.Assertions.assertFalse; |
28 | 23 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
29 | | -import static org.junit.jupiter.api.Assertions.assertNotSame; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertNull; |
30 | 25 | import static org.junit.jupiter.api.Assertions.assertSame; |
31 | 26 | import static org.junit.jupiter.api.Assertions.assertThrows; |
32 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
33 | 27 |
|
34 | 28 | @TestMethodOrder(MethodOrderer.OrderAnnotation.class) |
35 | 29 | class TestMachineBlock { |
36 | 30 |
|
37 | | - private static ServerMock server; |
38 | 31 | private static MockAddon addon; |
39 | 32 | private static MachineBlock machine; |
40 | | - private static Block block; |
41 | 33 | private static ItemStack input1; |
42 | 34 | private static ItemStack input2; |
43 | 35 | private static ItemStack output; |
44 | | - private static BlockMenu menu; |
45 | 36 |
|
46 | 37 | @BeforeAll |
47 | 38 | public static void load() { |
48 | | - server = MockBukkit.mock(); |
| 39 | + MockBukkit.mock(); |
49 | 40 | addon = MockBukkit.load(MockAddon.class); |
50 | 41 | Slimefun.getCfg().setValue("URID.enable-tickers", true); |
51 | 42 | machine = new MachineBlock(new SubGroup("key", new ItemStack(Material.DIAMOND)), |
52 | 43 | new SlimefunItemStack("ID", Material.STONE, "name"), |
53 | 44 | RecipeType.ANCIENT_ALTAR, new ItemStack[0]); |
54 | | - block = server.addSimpleWorld("").getBlockAt(0, 0, 0); |
55 | 45 | output = new CustomItemStack(SlimefunItems.SALT, 2); |
56 | 46 | input1 = SlimefunItems.COPPER_DUST; |
57 | 47 | input2 = new ItemStack(Material.NETHERITE_BLOCK, 2); |
@@ -80,102 +70,40 @@ void testRegister() { |
80 | 70 |
|
81 | 71 | @Test |
82 | 72 | @Order(1) |
83 | | - void testBlockMenuPreset() { |
84 | | - BlockMenuPreset preset = BlockMenuPreset.getPreset(machine.getId()); |
85 | | - assertNotNull(preset); |
86 | | - menu = new BlockMenu(preset, block.getLocation()); |
87 | | - } |
88 | | - |
89 | | - @Test |
90 | | - @Order(2) |
91 | 73 | void testAddRecipes() { |
92 | 74 | machine.addRecipe(output, input1, input2); |
93 | 75 | assertThrows(IllegalArgumentException.class, () -> machine.addRecipe(output)); |
94 | 76 | } |
95 | 77 |
|
96 | | - @Test |
97 | | - @Order(3) |
98 | | - void testTicksPerOutput() { |
99 | | - assertFalse(machine.process(block, menu)); |
100 | | - server.getScheduler().performOneTick(); |
101 | | - assertTrue(machine.process(block, menu)); |
102 | | - server.getScheduler().performOneTick(); |
103 | | - assertFalse(machine.process(block, menu)); |
104 | | - } |
105 | | - |
106 | 78 | @Test |
107 | 79 | void testProcess() { |
108 | | - assertFalse(machine.process(block, menu)); |
109 | | - |
110 | | - menu.replaceExistingItem(19, input1.clone()); |
111 | | - menu.replaceExistingItem(20, input2.clone()); |
112 | | - menu.replaceExistingItem(24, null); |
113 | | - menu.replaceExistingItem(24, null); |
114 | | - |
115 | | - assertTrue(machine.process(block, menu)); |
116 | | - assertNotSame(output, menu.getItemInSlot(24)); |
117 | | - assertEquals(output, menu.getItemInSlot(24)); |
118 | | - assertEquals(0, menu.getItemInSlot(19).getAmount()); |
119 | | - assertEquals(0, menu.getItemInSlot(20).getAmount()); |
120 | | - } |
| 80 | + ItemStack[] input = new ItemStack[2]; |
| 81 | + assertNull(machine.getOutput(input)); |
121 | 82 |
|
122 | | - @Test |
123 | | - void testShapelessProcessTwice() { |
124 | | - menu.replaceExistingItem(19, new CustomItemStack(input2, 4)); |
125 | | - menu.replaceExistingItem(20, new CustomItemStack(input1, 2)); |
126 | | - menu.replaceExistingItem(24, null); |
127 | | - menu.replaceExistingItem(25, null); |
128 | | - |
129 | | - assertTrue(machine.process(block, menu)); |
130 | | - assertEquals(2, menu.getItemInSlot(24).getAmount()); |
131 | | - assertEquals(2, menu.getItemInSlot(19).getAmount()); |
132 | | - assertEquals(1, menu.getItemInSlot(20).getAmount()); |
133 | | - |
134 | | - assertTrue(machine.process(block, menu)); |
135 | | - assertEquals(4, menu.getItemInSlot(24).getAmount()); |
136 | | - assertEquals(0, menu.getItemInSlot(19).getAmount()); |
137 | | - assertEquals(0, menu.getItemInSlot(20).getAmount()); |
138 | | - } |
| 83 | + input[0] = input1.clone(); |
| 84 | + input[1] = input2.clone(); |
| 85 | + MachineBlockRecipe out = machine.getOutput(input); |
139 | 86 |
|
140 | | - @Test |
141 | | - void testSplitOutput() { |
142 | | - menu.replaceExistingItem(19, new CustomItemStack(input2, 2)); |
143 | | - menu.replaceExistingItem(20, new CustomItemStack(input1, 1)); |
144 | | - menu.replaceExistingItem(24, new CustomItemStack(output, 63)); |
145 | | - menu.replaceExistingItem(25, null); |
146 | | - |
147 | | - assertTrue(machine.process(block, menu)); |
148 | | - assertEquals(64, menu.getItemInSlot(24).getAmount()); |
149 | | - assertEquals(output, menu.getItemInSlot(25)); |
150 | | - } |
| 87 | + assertNotNull(out); |
| 88 | + assertSame(output, out.output); |
151 | 89 |
|
152 | | - @Test |
153 | | - void testPartialOutput() { |
154 | | - menu.replaceExistingItem(19, new CustomItemStack(input2, 2)); |
155 | | - menu.replaceExistingItem(20, new CustomItemStack(input1, 1)); |
156 | | - menu.replaceExistingItem(24, new CustomItemStack(output, 64)); |
157 | | - menu.replaceExistingItem(25, new CustomItemStack(output, 63)); |
158 | | - |
159 | | - assertTrue(machine.process(block, menu)); |
160 | | - assertEquals(64, menu.getItemInSlot(24).getAmount()); |
161 | | - assertEquals(64, menu.getItemInSlot(25).getAmount()); |
162 | | - assertEquals(0, menu.getItemInSlot(19).getAmount()); |
163 | | - assertEquals(0, menu.getItemInSlot(20).getAmount()); |
164 | | - } |
| 90 | + out.consume(); |
165 | 91 |
|
166 | | - @Test |
167 | | - void testNoRoom() { |
168 | | - menu.replaceExistingItem(19, new CustomItemStack(input2, 2)); |
169 | | - menu.replaceExistingItem(20, new CustomItemStack(input1, 1)); |
170 | | - menu.replaceExistingItem(24, new CustomItemStack(output, 64)); |
171 | | - menu.replaceExistingItem(25, new CustomItemStack(output, 64)); |
| 92 | + assertEquals(0, input[0].getAmount()); |
| 93 | + assertEquals(0, input[1].getAmount()); |
| 94 | + assertNull(machine.getOutput(input)); |
| 95 | + |
| 96 | + input[0] = new CustomItemStack(input2, 4); |
| 97 | + input[1] = new CustomItemStack(input1, 2); |
| 98 | + |
| 99 | + out = machine.getOutput(input); |
172 | 100 |
|
173 | | - assertFalse(machine.process(block, menu)); |
| 101 | + assertNotNull(out); |
174 | 102 |
|
175 | | - menu.replaceExistingItem(24, new CustomItemStack(input1, 1)); |
176 | | - menu.replaceExistingItem(25, new CustomItemStack(input2, 1)); |
| 103 | + out.consume(); |
177 | 104 |
|
178 | | - assertFalse(machine.process(block, menu)); |
| 105 | + assertEquals(2, input[0].getAmount()); |
| 106 | + assertEquals(1, input[1].getAmount()); |
179 | 107 | } |
180 | 108 |
|
181 | 109 | } |
0 commit comments