Fix #2850 Fetching cooking time based on recipe. Thanks to SimonFlapse

* Added new method cookingTime(), replacing totalCookingTime
* Added GameTest for validating smelting times
This commit is contained in:
Simon 2022-03-27 15:15:22 +02:00 committed by GitHub
parent d2c146b257
commit c61398c950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 244 additions and 58 deletions

View file

@ -28,7 +28,7 @@ import net.minecraft.item.ItemConvertible
import net.minecraft.item.ItemStack
import net.minecraft.test.TestContext
import net.minecraft.util.math.BlockPos
import techreborn.blockentity.machine.GenericMachineBlockEntity
import reborncore.common.blockentity.MachineBaseBlockEntity
import techreborn.init.TRContent
class TRTestContext extends TestContext {
@ -55,6 +55,20 @@ class TRTestContext extends TestContext {
}
}
def machine(TRContent.Machine machine, @DelegatesTo(MachineContext) Closure machineContextClosure) {
def machinePos = new BlockPos(0, 1, 0)
setBlockState(machinePos, machine.block)
waitAndRun(5) {
try {
new MachineContext(machinePos).with(machineContextClosure)
} catch (e) {
e.printStackTrace()
throw e
}
}
}
class MachineContext {
final BlockPos machinePos
@ -100,14 +114,14 @@ class TRTestContext extends TestContext {
}
}
GenericMachineBlockEntity getBlockEntity() {
MachineBaseBlockEntity getBlockEntity() {
def be = getBlockEntity(machinePos)
if (!be) {
throwPositionedException("Failed to get machine block entity", machinePos)
}
return be as GenericMachineBlockEntity
return be as MachineBaseBlockEntity
}
}
}

View file

@ -0,0 +1,51 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 TechReborn
*
* 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.
*/
//file:noinspection GrMethodMayBeStatic
package techreborn.test.machine
import net.minecraft.item.Items
import net.minecraft.test.GameTest
import techreborn.blockentity.machine.iron.IronAlloyFurnaceBlockEntity
import techreborn.config.TechRebornConfig
import techreborn.init.TRContent
import techreborn.test.TRGameTest
import techreborn.test.TRTestContext
class IronAlloyFurnaceTest extends TRGameTest {
@GameTest(structureName = "fabric-gametest-api-v1:empty", tickLimit = 2000)
def testIronAlloyFurnaceElectrumAlloyIngot(TRTestContext context) {
/**
* Test that the Iron Alloy Furnace smelts a gold ingot and a silver ingot into an electrum alloy ingot in 200
* Verifies: Issue #2850
*/
context.machine(TRContent.Machine.IRON_ALLOY_FURNACE) {
input(Items.COAL_BLOCK, IronAlloyFurnaceBlockEntity.FUEL_SLOT)
input(Items.GOLD_INGOT, IronAlloyFurnaceBlockEntity.INPUT_SLOT_1)
input(TRContent.Ingots.SILVER, IronAlloyFurnaceBlockEntity.INPUT_SLOT_2)
expectOutput(TRContent.Ingots.ELECTRUM, (int) (200 / TechRebornConfig.cookingScale), IronAlloyFurnaceBlockEntity.OUTPUT_SLOT)
}
}
}

View file

@ -0,0 +1,65 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 TechReborn
*
* 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.
*/
//file:noinspection GrMethodMayBeStatic
package techreborn.test.machine
import net.minecraft.item.Items
import net.minecraft.test.GameTest
import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity
import techreborn.config.TechRebornConfig
import techreborn.init.TRContent
import techreborn.test.TRGameTest
import techreborn.test.TRTestContext
class IronFurnaceTest extends TRGameTest {
@GameTest(structureName = "fabric-gametest-api-v1:empty", tickLimit = 2000)
def testIronFurnaceSmeltRawIron(TRTestContext context) {
/**
* Test that the Iron Furnace smelts a raw iron ore into an iron ingot in 200 ticks
* Verifies: Issue #2850
*/
context.machine(TRContent.Machine.IRON_FURNACE) {
input(Items.COAL_BLOCK, IronFurnaceBlockEntity.FUEL_SLOT)
input(Items.RAW_IRON, IronFurnaceBlockEntity.INPUT_SLOT)
expectOutput(Items.IRON_INGOT, (int) (200 / TechRebornConfig.cookingScale), IronFurnaceBlockEntity.OUTPUT_SLOT)
}
}
@GameTest(structureName = "fabric-gametest-api-v1:empty", tickLimit = 2000)
def testIronFurnaceSmeltRawIronBlock(TRTestContext context) {
/**
* Test that the Iron Furnace smelts a raw iron block into an iron block in 1500 ticks instead of 200
* Verifies: Issue #2850
*/
context.machine(TRContent.Machine.IRON_FURNACE) {
input(Items.COAL_BLOCK, IronFurnaceBlockEntity.FUEL_SLOT)
input(Items.RAW_IRON_BLOCK, IronFurnaceBlockEntity.INPUT_SLOT)
expectOutput(Items.IRON_BLOCK, (int) (1500 / TechRebornConfig.cookingScale), IronFurnaceBlockEntity.OUTPUT_SLOT)
}
}
}

View file

@ -6,8 +6,10 @@
"environment": "*",
"entrypoints": {
"fabric-gametest" : [
"techreborn.test.machine.GrinderTest",
"techreborn.test.recipe.RecipeSyncTests"
"techreborn.test.machine.GrinderTest",
"techreborn.test.machine.IronFurnaceTest",
"techreborn.test.machine.IronAlloyFurnaceTest",
"techreborn.test.recipe.RecipeSyncTests"
]
}
}