Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public long getEuProduction(List<ConfigurableFluidStack> fluidInputs,

long euProduced = 0;

// Consume from the buffer first
euProduced += euBuffer;
euBuffer = 0;

for (ConfigurableFluidStack stack : fluidInputs) {
Fluid fluid = stack.getResource().getFluid();
if (fluidEUProductionMap.accept(fluid) && stack.getAmount() > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* MIT License
*
* Copyright (c) 2020 Azercoco & Technici4n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package aztech.modern_industrialization.test;

import aztech.modern_industrialization.MI;
import aztech.modern_industrialization.MIFluids;
import aztech.modern_industrialization.machines.blockentities.GeneratorMachineBlockEntity;
import aztech.modern_industrialization.test.framework.MIGameTest;
import aztech.modern_industrialization.test.framework.MIGameTestHelper;
import aztech.modern_industrialization.thirdparty.fabrictransfer.api.transaction.Transaction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;

public class GeneratorTests {
/**
* Regression test for <a href="https://github.com/AztechMC/Modern-Industrialization/issues/1152">issue 1152</a>:
* "EU is left in a hidden buffer when Diesel Generator runs out of fuel".
*/
@MIGameTest
public void testGeneratorEmptiesEuBuffer(MIGameTestHelper helper) {
var generatorPos = new BlockPos(0, 1, 0);
var lvDieselGeneratorBlock = BuiltInRegistries.BLOCK.getOptional(MI.id("lv_diesel_generator")).orElseThrow();
helper.setBlock(generatorPos, lvDieselGeneratorBlock);

var dieselGenerator = (GeneratorMachineBlockEntity) helper.getBlockEntity(generatorPos);

try (var tx = Transaction.openOuter()) {
long inserted = dieselGenerator.getInventory().fluidStorage.insert(MIFluids.BIODIESEL.variant(), 1, tx);
helper.assertValueEqual(inserted, 1L, "inserted biodiesel");
tx.commit();
}

// Should produce 64 per tick: 192 after 3 ticks and only 250 (the biodiesel value) after 4 ticks
helper.startSequence()
.thenIdle(3)
.thenExecute(() -> helper.assertEnergy(generatorPos, 192, Direction.NORTH))
.thenIdle(1)
.thenExecute(() -> helper.assertEnergy(generatorPos, 250, Direction.NORTH))
.thenSucceed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package aztech.modern_industrialization.test.framework;

import aztech.modern_industrialization.MIBlock;
import aztech.modern_industrialization.api.energy.EnergyApi;
import aztech.modern_industrialization.blocks.storage.tank.creativetank.CreativeTankBlockEntity;
import aztech.modern_industrialization.materials.MIMaterials;
import aztech.modern_industrialization.materials.Material;
Expand All @@ -35,12 +36,14 @@
import aztech.modern_industrialization.thirdparty.fabrictransfer.api.fluid.FluidVariant;
import java.util.function.Consumer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.gametest.framework.GameTestInfo;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.capabilities.Capabilities;
import org.jetbrains.annotations.Nullable;

public class MIGameTestHelper extends GameTestHelper {
public MIGameTestHelper(GameTestInfo testInfo) {
Expand Down Expand Up @@ -122,4 +125,15 @@ public void assertNoFluid(BlockPos pos) {
}
}
}

public void assertEnergy(BlockPos pos, long energy, @Nullable Direction side) {
var miEnergyHandler = getLevel().getCapability(EnergyApi.SIDED, absolutePos(pos), side);
if (miEnergyHandler == null) {
fail("Could not find energy handler", pos);
}
long storedEnergy = miEnergyHandler.getAmount();
if (storedEnergy != energy) {
fail("Expected energy to be " + energy + ", was " + storedEnergy, pos);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import aztech.modern_industrialization.MI;
import aztech.modern_industrialization.test.FluidPipeTests;
import aztech.modern_industrialization.test.GeneratorTests;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand All @@ -37,7 +38,8 @@ private MIGameTests() {
}

private static final List<Class<?>> TEST_CLASSES = List.of(
FluidPipeTests.class);
FluidPipeTests.class,
GeneratorTests.class);

@GameTestGenerator
public static List<TestFunction> generateTests() {
Expand Down
Loading