diff --git a/gradle.properties b/gradle.properties index f9f67901..1e099e67 100644 --- a/gradle.properties +++ b/gradle.properties @@ -42,4 +42,4 @@ org.gradle.daemon=false org.gradle.caching=true # Common dependencies -cyclopscore_version=1.25.1-627 +cyclopscore_version=1.25.2-634 diff --git a/loader-common/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsCommon.java b/loader-common/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsCommon.java new file mode 100644 index 00000000..7c27ab3b --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsCommon.java @@ -0,0 +1,116 @@ +package org.cyclops.everlastingabilities.gametest; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.gametest.framework.GameTest; +import net.minecraft.gametest.framework.GameTestHelper; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.GameType; +import org.cyclops.everlastingabilities.EverlastingAbilitiesInstance; +import org.cyclops.everlastingabilities.Reference; +import org.cyclops.everlastingabilities.api.Ability; +import org.cyclops.everlastingabilities.api.IAbilityType; +import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStore; +import org.cyclops.everlastingabilities.helper.IAbilityHelpers; + +import java.util.Optional; + +/** + * @author rubensworks + */ +public class GameTestsCommon { + + public static final String TEMPLATE_EMPTY = "cyclopscore:empty"; + public static final BlockPos POS = BlockPos.ZERO; + + @GameTest(template = TEMPLATE_EMPTY) + public void testPlayerAbilityNotEnoughXp(GameTestHelper helper) { + helper.succeedIf(() -> { + Player player = helper.makeMockPlayer(GameType.SURVIVAL); + + // Assign XP to player + player.totalExperience = 0; + + // Determine an ability + Registry registry = getAbilityHelpers().getRegistry(helper.getLevel().registryAccess()); + Holder abilityType = registry.getHolderOrThrow(ResourceKey.create(registry.key(), ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "effect/speed"))); + Ability ability = new Ability(abilityType, 3); + + // Add ability + helper.assertTrue(getAbilityHelpers().addPlayerAbility( + player, + ability, + false, + true + ).isEmpty(), "Expected not to be addable in simulate-mode"); + + // Check if player has an ability store + Optional store = getAbilityHelpers().getEntityAbilityStore(player); + helper.assertTrue(store.isPresent(), "Player has no ability store"); + + // Check if ability was not added + helper.assertValueEqual(store.get().getAbilities().size(), 0, "Expect ability store of size 1"); + }); + } + + @GameTest(template = TEMPLATE_EMPTY) + public void testPlayerAbilityValid(GameTestHelper helper) { + helper.succeedIf(() -> { + Player player = helper.makeMockPlayer(GameType.SURVIVAL); + + // Assign XP to player + player.totalExperience = 300; + + // Determine an ability + Registry registry = getAbilityHelpers().getRegistry(helper.getLevel().registryAccess()); + Holder abilityType = registry.getHolderOrThrow(ResourceKey.create(registry.key(), ResourceLocation.fromNamespaceAndPath(Reference.MOD_ID, "effect/speed"))); + Ability ability = new Ability(abilityType, 3); + + // Add ability + helper.assertTrue(!getAbilityHelpers().addPlayerAbility( + player, + ability, + false, + true + ).isEmpty(), "Expected to be addable in simulate-mode"); + helper.assertTrue(!getAbilityHelpers().addPlayerAbility( + player, + ability, + true, + true + ).isEmpty(), "Expected to be addable"); + + // Check if player has an ability store + Optional store = getAbilityHelpers().getEntityAbilityStore(player); + helper.assertTrue(store.isPresent(), "Player has no ability store"); + + // Check if ability was added + helper.assertValueEqual(store.get().getAbilities().size(), 1, "Expect ability store of size 1"); + helper.assertTrue(store.get().getAbility(abilityType).getAbilityType() != null, "Expect ability type to be contained"); + helper.assertValueEqual(store.get().getAbility(abilityType).getAbilityTypeHolder(), abilityType, "Expect ability type to be correct"); + helper.assertValueEqual(store.get().getAbility(abilityType).getLevel(), 3, "Expect ability level to be correct"); + }); + } + + // TODO: max level exceeded + + // TODO: add same ab multiple times + + // TODO: add multiple abs + + // TODO: remove ab + + // TODO: onPlayerClone + + // TODO: interact with abilities of a totem/bottle item + + // TODO: commands? + + public static IAbilityHelpers getAbilityHelpers() { + return EverlastingAbilitiesInstance.MOD.getAbilityHelpers(); + } + +} diff --git a/loader-fabric/src/main/resources/fabric.mod.json b/loader-fabric/src/main/resources/fabric.mod.json index 80f9c53c..b567d95f 100644 --- a/loader-fabric/src/main/resources/fabric.mod.json +++ b/loader-fabric/src/main/resources/fabric.mod.json @@ -20,6 +20,9 @@ "entrypoints": { "main": [ "org.cyclops.everlastingabilities.EverlastingAbilitiesFabric" + ], + "fabric-gametest": [ + "org.cyclops.everlastingabilities.gametest.GameTestsCommon" ] }, diff --git a/loader-forge/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsLoaderForge.java b/loader-forge/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsLoaderForge.java new file mode 100644 index 00000000..d9ef23f3 --- /dev/null +++ b/loader-forge/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsLoaderForge.java @@ -0,0 +1,22 @@ +package org.cyclops.everlastingabilities.gametest; + +import net.minecraft.gametest.framework.GameTestGenerator; +import net.minecraft.gametest.framework.TestFunction; +import net.minecraftforge.gametest.GameTestHolder; +import org.cyclops.everlastingabilities.Reference; +import org.cyclops.cyclopscore.gametest.GameTestLoaderHelpers; + +import java.util.Collection; + +/** + * @author rubensworks + */ +@GameTestHolder(Reference.MOD_ID) +public class GameTestsLoaderForge extends GameTestsCommon { + @GameTestGenerator + public Collection generateCommonTests() throws InstantiationException, IllegalAccessException { + return GameTestLoaderHelpers.generateCommonTests(Reference.MOD_ID, new Class[]{ + GameTestsCommon.class + }); + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsLoaderNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsLoaderNeoForge.java new file mode 100644 index 00000000..8adb7f50 --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsLoaderNeoForge.java @@ -0,0 +1,22 @@ +package org.cyclops.everlastingabilities.gametest; + +import net.minecraft.gametest.framework.GameTestGenerator; +import net.minecraft.gametest.framework.TestFunction; +import net.neoforged.neoforge.gametest.GameTestHolder; +import org.cyclops.everlastingabilities.Reference; +import org.cyclops.cyclopscore.gametest.GameTestLoaderHelpers; + +import java.util.Collection; + +/** + * @author rubensworks + */ +@GameTestHolder(Reference.MOD_ID) +public class GameTestsLoaderNeoForge extends GameTestsCommon { + @GameTestGenerator + public Collection generateCommonTests() throws InstantiationException, IllegalAccessException { + return GameTestLoaderHelpers.generateCommonTests(Reference.MOD_ID, new Class[]{ + GameTestsCommon.class + }); + } +}