-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a16155
commit 711049e
Showing
5 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
loader-common/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsCommon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IAbilityType> registry = getAbilityHelpers().getRegistry(helper.getLevel().registryAccess()); | ||
Holder<IAbilityType> 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<IMutableAbilityStore> 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<IAbilityType> registry = getAbilityHelpers().getRegistry(helper.getLevel().registryAccess()); | ||
Holder<IAbilityType> 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<IMutableAbilityStore> 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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...r-forge/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsLoaderForge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestFunction> generateCommonTests() throws InstantiationException, IllegalAccessException { | ||
return GameTestLoaderHelpers.generateCommonTests(Reference.MOD_ID, new Class[]{ | ||
GameTestsCommon.class | ||
}); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...orge/src/main/java/org/cyclops/everlastingabilities/gametest/GameTestsLoaderNeoForge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestFunction> generateCommonTests() throws InstantiationException, IllegalAccessException { | ||
return GameTestLoaderHelpers.generateCommonTests(Reference.MOD_ID, new Class[]{ | ||
GameTestsCommon.class | ||
}); | ||
} | ||
} |