Fix recipe syncing, improve (add) error handling.
This commit is contained in:
parent
bd6bcf55ab
commit
fa657d46e8
24 changed files with 273 additions and 126 deletions
|
@ -24,6 +24,7 @@
|
|||
|
||||
package techreborn.test
|
||||
|
||||
import groovy.util.logging.Slf4j
|
||||
import net.fabricmc.fabric.api.gametest.v1.FabricGameTest
|
||||
import net.minecraft.test.TestContext
|
||||
|
||||
|
@ -34,9 +35,25 @@ import java.lang.reflect.Method
|
|||
*
|
||||
* All test methods should accept 1 argument of TRTestContext
|
||||
*/
|
||||
@Slf4j
|
||||
abstract class TRGameTest implements FabricGameTest {
|
||||
@Override
|
||||
void invokeTestMethod(TestContext context, Method method) {
|
||||
method.invoke(this, new TRTestContext(context))
|
||||
try {
|
||||
method.invoke(this, new TRTestContext(context))
|
||||
} catch (TRGameTestException gameTestException) {
|
||||
log.error("Test ${method.name} failed with message ${gameTestException.message}", gameTestException.cause)
|
||||
log.error(gameTestException.cause.message)
|
||||
throw gameTestException
|
||||
} catch (Throwable throwable) {
|
||||
log.error("Test ${method.name} failed", throwable)
|
||||
throw throwable
|
||||
}
|
||||
}
|
||||
|
||||
static class TRGameTestException extends AssertionError {
|
||||
TRGameTestException(String message, Throwable cause) {
|
||||
super(message, cause)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package techreborn.test.recipe
|
||||
|
||||
import com.google.common.truth.Truth
|
||||
import net.minecraft.test.GameTest
|
||||
import reborncore.common.crafting.RebornRecipe
|
||||
import reborncore.common.crafting.RebornRecipeType
|
||||
import reborncore.common.crafting.RecipeManager
|
||||
import techreborn.test.TRGameTest
|
||||
import techreborn.test.TRTestContext
|
||||
|
||||
/**
|
||||
* A bit of a mess, but checks that we can ser/de all recipes to and from json.
|
||||
*/
|
||||
class RecipeSyncTests extends TRGameTest {
|
||||
@GameTest(structureName = "fabric-gametest-api-v1:empty", tickLimit = 150)
|
||||
def testRecipes(TRTestContext context) {
|
||||
|
||||
def recipeTypes = RecipeManager.getRecipeTypes("techreborn")
|
||||
|
||||
recipeTypes.each { type ->
|
||||
def recipes = type.getRecipes(context.world)
|
||||
recipes.each { recipe ->
|
||||
try {
|
||||
testRecipe(type, recipe)
|
||||
} catch (Throwable t) {
|
||||
throw new TRGameTestException(recipe.id.toString(), t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.complete()
|
||||
}
|
||||
|
||||
def <R extends RebornRecipe> void testRecipe(RebornRecipeType<R> type, R recipe) {
|
||||
def firstJson = type.toJson(recipe, true).deepCopy()
|
||||
def newRecipe = type.read(recipe.id, firstJson)
|
||||
def secondJson = type.toJson(newRecipe, true).deepCopy()
|
||||
|
||||
Truth.assertThat(firstJson.toString())
|
||||
.isEqualTo(secondJson.toString())
|
||||
|
||||
// And check we can create a data json
|
||||
def dataJson = type.toJson(newRecipe, false).deepCopy()
|
||||
}
|
||||
}
|
|
@ -6,7 +6,8 @@
|
|||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"fabric-gametest" : [
|
||||
"techreborn.test.machine.GrinderTest"
|
||||
"techreborn.test.machine.GrinderTest",
|
||||
"techreborn.test.recipe.RecipeSyncTests"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ public class BlastFurnaceRecipeSerde extends RebornRecipeSerde<BlastFurnaceRecip
|
|||
}
|
||||
|
||||
@Override
|
||||
public void collectJsonData(BlastFurnaceRecipe recipe, JsonObject jsonObject) {
|
||||
public void collectJsonData(BlastFurnaceRecipe recipe, JsonObject jsonObject, boolean networkSync) {
|
||||
jsonObject.addProperty("heat", recipe.getHeat());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class FusionReactorRecipeSerde extends RebornRecipeSerde<FusionReactorRec
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void collectJsonData(FusionReactorRecipe recipe, JsonObject jsonObject) {
|
||||
protected void collectJsonData(FusionReactorRecipe recipe, JsonObject jsonObject, boolean networkSync) {
|
||||
jsonObject.addProperty("start-power", recipe.getStartEnergy());
|
||||
jsonObject.addProperty("min-size", recipe.getMinSize());
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@ import net.minecraft.recipe.ShapedRecipe;
|
|||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import reborncore.common.crafting.RebornRecipeType;
|
||||
import reborncore.common.crafting.ShapedRecipeHelper;
|
||||
import reborncore.common.crafting.ingredient.RebornIngredient;
|
||||
import reborncore.common.crafting.serde.RebornRecipeSerde;
|
||||
import techreborn.api.recipe.recipes.RollingMachineRecipe;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RollingMachineRecipeSerde extends RebornRecipeSerde<RollingMachineRecipe> {
|
||||
@Override
|
||||
|
@ -23,8 +25,9 @@ public class RollingMachineRecipeSerde extends RebornRecipeSerde<RollingMachineR
|
|||
}
|
||||
|
||||
@Override
|
||||
public void collectJsonData(RollingMachineRecipe recipe, JsonObject jsonObject) {
|
||||
jsonObject.add("shaped", recipe.getShapedRecipeJson());
|
||||
public void collectJsonData(RollingMachineRecipe recipe, JsonObject jsonObject, boolean networkSync) {
|
||||
final JsonObject shapedRecipeJson = networkSync ? ShapedRecipeHelper.rewriteForNetworkSync(recipe.getShapedRecipeJson()) : recipe.getShapedRecipeJson();
|
||||
jsonObject.add("shaped", Objects.requireNonNull(shapedRecipeJson));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +43,7 @@ public class RollingMachineRecipeSerde extends RebornRecipeSerde<RollingMachineR
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writeIngredients(RollingMachineRecipe recipe, JsonObject jsonObject) {
|
||||
protected void writeIngredients(RollingMachineRecipe recipe, JsonObject jsonObject, boolean networkSync) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue