|
| 1 | +/* |
| 2 | + * MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2020 Azercoco & Technici4n |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | +package aztech.modern_industrialization.test; |
| 25 | + |
| 26 | +import aztech.modern_industrialization.MI; |
| 27 | +import aztech.modern_industrialization.MIFluids; |
| 28 | +import aztech.modern_industrialization.machines.blockentities.GeneratorMachineBlockEntity; |
| 29 | +import aztech.modern_industrialization.test.framework.MIGameTest; |
| 30 | +import aztech.modern_industrialization.test.framework.MIGameTestHelper; |
| 31 | +import aztech.modern_industrialization.thirdparty.fabrictransfer.api.transaction.Transaction; |
| 32 | +import net.minecraft.core.BlockPos; |
| 33 | +import net.minecraft.core.Direction; |
| 34 | +import net.minecraft.core.registries.BuiltInRegistries; |
| 35 | + |
| 36 | +public class GeneratorTests { |
| 37 | + /** |
| 38 | + * Regression test for <a href="https://github.com/AztechMC/Modern-Industrialization/issues/1152">issue 1152</a>: |
| 39 | + * "EU is left in a hidden buffer when Diesel Generator runs out of fuel". |
| 40 | + */ |
| 41 | + @MIGameTest |
| 42 | + public void testGeneratorEmptiesEuBuffer(MIGameTestHelper helper) { |
| 43 | + var generatorPos = new BlockPos(0, 1, 0); |
| 44 | + var lvDieselGeneratorBlock = BuiltInRegistries.BLOCK.getOptional(MI.id("lv_diesel_generator")).orElseThrow(); |
| 45 | + helper.setBlock(generatorPos, lvDieselGeneratorBlock); |
| 46 | + |
| 47 | + var dieselGenerator = (GeneratorMachineBlockEntity) helper.getBlockEntity(generatorPos); |
| 48 | + |
| 49 | + try (var tx = Transaction.openOuter()) { |
| 50 | + long inserted = dieselGenerator.getInventory().fluidStorage.insert(MIFluids.BIODIESEL.variant(), 1, tx); |
| 51 | + helper.assertValueEqual(inserted, 1L, "inserted biodiesel"); |
| 52 | + tx.commit(); |
| 53 | + } |
| 54 | + |
| 55 | + // Should produce 64 per tick: 192 after 3 ticks and only 250 (the biodiesel value) after 4 ticks |
| 56 | + helper.startSequence() |
| 57 | + .thenIdle(3) |
| 58 | + .thenExecute(() -> helper.assertEnergy(generatorPos, 192, Direction.NORTH)) |
| 59 | + .thenIdle(1) |
| 60 | + .thenExecute(() -> helper.assertEnergy(generatorPos, 250, Direction.NORTH)) |
| 61 | + .thenSucceed(); |
| 62 | + } |
| 63 | +} |
0 commit comments