Skip to content

Commit

Permalink
Update GameTests to work in .1
Browse files Browse the repository at this point in the history
  • Loading branch information
Witixin1512 committed Feb 24, 2024
1 parent fc780b7 commit 615c12d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
package com.blamejared.crafttweaker.gametest.test.api.recipe.replacer;

import com.blamejared.crafttweaker.api.CraftTweakerAPI;
import com.blamejared.crafttweaker.gametest.CraftTweakerGameTest;
import com.blamejared.crafttweaker.gametest.framework.ScriptBuilder;
import com.blamejared.crafttweaker.gametest.framework.annotation.CraftTweakerGameTestHolder;
import com.blamejared.crafttweaker.gametest.framework.annotation.TestModifier;
import com.blamejared.crafttweaker.gametest.logging.appender.GameTestLoggerAppender;
import com.blamejared.crafttweaker.impl.recipe.replacement.ReplacerRegistry;
import com.blamejared.crafttweaker.impl.script.scriptrun.GameTestScriptRunner;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeManager;

import java.util.Optional;

import static org.hamcrest.MatcherAssert.assertThat;

@CraftTweakerGameTestHolder
public class ReplacerGameTests implements CraftTweakerGameTest {

@GameTest(template = "crafttweaker:empty")
@TestModifier(implicitSuccession = true)
public void testReplacer(GameTestHelper helper, ScriptBuilder builder) {
builder.file("recipe/replacer/basic_replacer.zs");

GameTestLoggerAppender.QueryableLog log = GameTestScriptRunner.runScripts(helper, builder);
log.assertNoErrors();
log.assertNoWarnings();

RecipeManager recipeManager = helper.getLevel().getServer().getRecipeManager();

//Test that the recipes were indeed replaced
Optional<RecipeHolder<?>> recipe = recipeManager.byKey(new ResourceLocation("crafttweaker:autogenerated/replacer/minecraft.diamond_boots.1"));
boolean assertion = recipe.isPresent() && recipe.get().value().getIngredients().get(0).test(Items.APPLE.getDefaultInstance());
assertThat("Replacer did not work", assertion);
}

@GameTest(template = "crafttweaker:empty")
@TestModifier(implicitSuccession = true)
public void testCustomFilteringRule(GameTestHelper helper, ScriptBuilder builder) {
Expand All @@ -53,9 +33,9 @@ public void testCustomFilteringRule(GameTestHelper helper, ScriptBuilder builder
RecipeManager recipeManager = helper.getLevel().getServer().getRecipeManager();

//Test that the recipes were indeed replaced
Optional<RecipeHolder<?>> recipe = recipeManager.byKey(new ResourceLocation("crafttweaker:autogenerated/replacer/minecraft.diamond_block.1"));
Optional<RecipeHolder<?>> unreplaced = recipeManager.byKey(new ResourceLocation("minecraft:diamond_boots"));
boolean wasReplaced = recipe.isPresent() && recipe.get().value().getIngredients().get(0).test(Items.APPLE.getDefaultInstance());
Optional<? extends Recipe<?>> recipe = recipeManager.byKey(new ResourceLocation("crafttweaker:autogenerated/replacer/minecraft.diamond_block.1"));
Optional<? extends Recipe<?>> unreplaced = recipeManager.byKey(new ResourceLocation("minecraft:diamond_boots"));
boolean wasReplaced = recipe.isPresent() && recipe.get().getIngredients().get(0).test(Items.APPLE.getDefaultInstance());
//Check that the replaced one was indeed replaced and that the other one was not
assertThat("Custom filtering rule did not work", wasReplaced && unreplaced.isPresent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import crafttweaker.api.recipe.replacement.type.CustomFilteringRule;
import crafttweaker.api.ingredient.IIngredient;

Replacer.create()
.filter(CustomFilteringRule.of((holder) => holder.value.ingredients.length > 6))
.filter(CustomFilteringRule.of(rec => rec.ingredients.length > 6))
.replace<IIngredient>(
<recipecomponent:crafttweaker:input/ingredients>,
<targetingstrategy:crafttweaker:shallow>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ private CustomFilteringRule(final BiPredicate<IRecipeManager<?>, RecipeHolder<?>
*
* @since 10.0.0
*/
@ZenCodeType.Method
public static CustomFilteringRule of(final Predicate<RecipeHolder<?>> predicate) {

return new CustomFilteringRule((a, b) -> predicate.test(b), false);
Expand All @@ -64,7 +63,6 @@ public static CustomFilteringRule of(final Predicate<RecipeHolder<?>> predicate)
*
* @since 10.0.0
*/
@ZenCodeType.Method
public static CustomFilteringRule of(final BiPredicate<IRecipeManager<?>, RecipeHolder<?>> predicate) {

return new CustomFilteringRule(predicate, true);
Expand All @@ -83,9 +81,9 @@ public static CustomFilteringRule of(final BiPredicate<IRecipeManager<?>, Recipe
* @since 11.0.0
*/
@ZenCodeType.Method("of")
public static CustomFilteringRule ofZen(final Predicate<Recipe<Container>> predicate) {
public static CustomFilteringRule ofZen(final Predicate<RecipeHolder<Container>> predicate) {

return of(GenericUtil.<Predicate<Recipe<?>>>uncheck(predicate));
return of(GenericUtil.<Predicate<RecipeHolder<?>>>uncheck(predicate));
}

/**
Expand All @@ -102,9 +100,9 @@ public static CustomFilteringRule ofZen(final Predicate<Recipe<Container>> predi
* @since 11.0.0
*/
@ZenCodeType.Method("of")
public static CustomFilteringRule ofZen(final BiPredicate<IRecipeManager<Recipe<Container>>, Recipe<Container>> predicate) {
public static CustomFilteringRule ofZen(final BiPredicate<IRecipeManager<Recipe<Container>>, RecipeHolder<Recipe<Container>>> predicate) {

return of(GenericUtil.<BiPredicate<IRecipeManager<?>, Recipe<?>>>uncheck(predicate));
return of(GenericUtil.<BiPredicate<IRecipeManager<?>, RecipeHolder<?>>>uncheck(predicate));
}

@Override
Expand Down

0 comments on commit 615c12d

Please sign in to comment.