Skip to content

Commit

Permalink
Advancement testing
Browse files Browse the repository at this point in the history
  • Loading branch information
legobmw99 committed Jan 25, 2025
1 parent f0c788c commit 74a76b5
Show file tree
Hide file tree
Showing 21 changed files with 308 additions and 134 deletions.
2 changes: 2 additions & 0 deletions src/main/generated_resources/assets/allomancy/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"advancements.local_metallurgist.title": "Local Metallurgist!",
"advancements.metallic_collector.desc": "Collect every single metallic flake, even the useless ones",
"advancements.metallic_collector.title": "Metallic Collector",
"advancements.time_warp.desc": "Time travel? Not quite!",
"advancements.time_warp.title": "Sub-time bubble?",
"advancements.tin_foil_hat.desc": "Protect yourself, and be a bit paranoid too",
"advancements.tin_foil_hat.title": "Tin foil hat",
"allomancy.aluminum.black": "Black Aluminum Symbol",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"parent": "allomancy:main/metallurgist",
"criteria": {
"got_slowed_down": {
"conditions": {
"metal": "cadmium"
},
"trigger": "allomancy:metal_used_on_player"
},
"got_sped_up": {
"conditions": {
"metal": "bendalloy"
},
"trigger": "allomancy:metal_used_on_player"
}
},
"display": {
"description": {
"translate": "advancements.time_warp.desc"
},
"hidden": true,
"icon": {
"count": 1,
"id": "minecraft:clock"
},
"title": {
"translate": "advancements.time_warp.title"
}
},
"requirements": [
[
"got_slowed_down"
],
[
"got_sped_up"
]
],
"sends_telemetry_event": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"criteria": {
"attempted_chromium_manipulation": {
"conditions": {
"enhanced": false,
"metal": "chromium",
"player": [
{
Expand All @@ -23,7 +22,6 @@
},
"attempted_nicrosil_manipulation": {
"conditions": {
"enhanced": false,
"metal": "nicrosil",
"player": [
{
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/legobmw99/allomancy/datagen/Advancements.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;

import java.util.Optional;
Expand Down Expand Up @@ -112,14 +113,25 @@ public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolde
Component.translatable("advancements.tin_foil_hat.desc"), null, AdvancementType.TASK, true,
false, true)
.addCriterion("attempted_nicrosil_manipulation",
MetalUsedOnPlayerTrigger.TriggerInstance.instance(tinFoilPredicate, Metal.NICROSIL,
false))
MetalUsedOnPlayerTrigger.TriggerInstance.instance(tinFoilPredicate, Metal.NICROSIL))
.addCriterion("attempted_chromium_manipulation",
MetalUsedOnPlayerTrigger.TriggerInstance.instance(tinFoilPredicate, Metal.CHROMIUM,
false))
MetalUsedOnPlayerTrigger.TriggerInstance.instance(tinFoilPredicate, Metal.CHROMIUM))
.requirements(AdvancementRequirements.Strategy.OR)
.save(saver, "allomancy:main/tin_foil_hat");

Advancement.Builder
.advancement()
.parent(Advancement.Builder.advancement().build(Allomancy.rl("main/metallurgist")))
.display(Items.CLOCK, Component.translatable("advancements.time_warp.title"),
Component.translatable("advancements.time_warp.desc"), null, AdvancementType.TASK, true,
true, true)
.addCriterion("got_slowed_down",
MetalUsedOnPlayerTrigger.TriggerInstance.instance(null, Metal.CADMIUM))
.addCriterion("got_sped_up", MetalUsedOnPlayerTrigger.TriggerInstance.instance(null, Metal.BENDALLOY))
.requirements(AdvancementRequirements.Strategy.AND)
.save(saver, "allomancy:main/time_warp");


var ironGolemPredicate = EntityPredicate.wrap(EntityPredicate.Builder
.entity()
.of(registries.lookupOrThrow(Registries.ENTITY_TYPE),
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/legobmw99/allomancy/datagen/Languages.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ protected void addTranslations() {
add("advancements.coinshot.desc", "Kill a mob with the bag of coins.");
add("advancements.tin_foil_hat.title", "Tin foil hat");
add("advancements.tin_foil_hat.desc", "Protect yourself, and be a bit paranoid too");
add("advancements.time_warp.title", "Sub-time bubble?");
add("advancements.time_warp.desc", "Time travel? Not quite!");
add("advancements.consequences.title", "Consequences, Vin");
add("advancements.consequences.desc", "Learn what happens when you push on a much heavier target.");
add("advancements.going_loud.title", "Going Loud");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public Codec<TriggerInstance> codec() {
}

public void trigger(ServerPlayer player, Entity entity, Metal mt, boolean enhanced) {
if (entity instanceof ServerPlayer target && !player.equals(target)) {
ExtrasSetup.METAL_USED_ON_PLAYER_TRIGGER.get().trigger(target, mt, enhanced);
}
LootContext lootcontext = EntityPredicate.createContext(player, entity);
this.trigger(player, p_48112_ -> p_48112_.matches(lootcontext, mt, enhanced));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public static void onPlayerLoad(final PlayerEvent.LoadFromFile event) {

@SubscribeEvent
public static void onJoinWorld(final PlayerEvent.PlayerLoggedInEvent event) {
if (event.getEntity().level().isClientSide()) {
return;
}
if (event.getEntity() instanceof ServerPlayer player) {
if (!player.hasData(AllomancerAttachment.ALLOMANCY_DATA)) {
var data = player.getData(AllomancerAttachment.ALLOMANCY_DATA);
Expand Down Expand Up @@ -149,7 +146,8 @@ public static void onChangeDimension(final PlayerEvent.PlayerChangedDimensionEve

@SubscribeEvent
public static void onStartTracking(final PlayerEvent.StartTracking event) {
if (!event.getTarget().level().isClientSide && event.getTarget() instanceof ServerPlayer player) {
if (!event.getTarget().level().isClientSide && event.getTarget() instanceof ServerPlayer player &&
player.hasData(AllomancerAttachment.ALLOMANCY_DATA)) {
Network.syncAllomancerData(player);
}
}
Expand Down Expand Up @@ -195,11 +193,8 @@ public static void onEntityHurt(final LivingIncomingDamageEvent event) {
ExtrasSetup.METAL_USED_ON_ENTITY_TRIGGER
.get()
.trigger(source, event.getEntity(), Metal.CHROMIUM, data.isEnhanced());
if (event.getEntity() instanceof ServerPlayer player) {
ExtrasSetup.METAL_USED_ON_PLAYER_TRIGGER.get().trigger(player, Metal.CHROMIUM, data.isEnhanced());
if (!Emotional.hasTinFoilHat(player)) {
Enhancement.wipePlayer(player);
}
if (event.getEntity() instanceof ServerPlayer player && !Emotional.hasTinFoilHat(player)) {
Enhancement.wipePlayer(player);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ public static void tryPushPullEntity(EntityPushPullPayload payload, IPayloadCont

// Split the difference
} else if (!(target instanceof ThrowableItemProjectile)) {
if (target instanceof ServerPlayer targetPlayer) {
ExtrasSetup.METAL_USED_ON_PLAYER_TRIGGER
.get()
.trigger(targetPlayer, which, data.isEnhanced());
}
Physical.lurch(payload.force() / 2.0, target, player.blockPosition());
Physical.lurch(payload.force() / 2.0, player, target.blockPosition());
}
Expand Down Expand Up @@ -165,14 +160,10 @@ public static void updateEnhanced(EnhanceTimePayload payload, IPayloadContext ct

Entity e = source.level().getEntity(payload.entityID());
ExtrasSetup.METAL_USED_ON_ENTITY_TRIGGER.get().trigger(source, e, Metal.NICROSIL, data.isEnhanced());
if (e instanceof ServerPlayer target) {
ExtrasSetup.METAL_USED_ON_PLAYER_TRIGGER.get().trigger(target, Metal.NICROSIL, data.isEnhanced());
if (!Emotional.hasTinFoilHat(target)) {
target.getData(AllomancerAttachment.ALLOMANCY_DATA).setEnhanced(payload.enhanceTime());
// broadcast back to player and tracking
Network.sync(payload, target);

}
if (e instanceof ServerPlayer target && !Emotional.hasTinFoilHat(target)) {
target.getData(AllomancerAttachment.ALLOMANCY_DATA).setEnhanced(payload.enhanceTime());
// broadcast back to player and tracking
Network.sync(payload, target);
}
}).exceptionally(e -> {
Allomancy.LOGGER.error("Failed to handle sever updateEnhanced", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.legobmw99.allomancy.api.data.IAllomancerData;
import com.legobmw99.allomancy.api.enums.Metal;
import com.legobmw99.allomancy.modules.extras.ExtrasSetup;
import com.legobmw99.allomancy.modules.powers.data.AllomancerAttachment;
import com.legobmw99.allomancy.modules.powers.network.Network;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -36,8 +37,8 @@ public static void wipePlayer(ServerPlayer player) {
* Teleports a player to the given dimension and blockpos
*
* @param player The player to move
* @param world The server world. Fails if clientside
* @param dimension Dimension to call {@link Entity#changeDimension} on
* @param world The server world
* @param dimension Dimension to transport to
* @param pos BlockPos to move the player to using {@link Entity#teleportTo(double, double, double)}
*/
private static void teleport(ServerPlayer player, ServerLevel world, ResourceKey<Level> dimension, BlockPos pos) {
Expand Down Expand Up @@ -92,10 +93,11 @@ public static void wipeNearby(ServerPlayer curPlayer, ServerLevel level) {
int max = 20;
Vec3 negative = curPlayer.position().add(-max, -max, -max);
Vec3 positive = curPlayer.position().add(max, max, max);
level
.getEntitiesOfClass(ServerPlayer.class, new AABB(negative, positive))
.stream()
.filter(player -> !Emotional.hasTinFoilHat(player))
.forEach(Enhancement::wipePlayer);
level.getEntitiesOfClass(ServerPlayer.class, new AABB(negative, positive)).stream().forEach(player -> {
ExtrasSetup.METAL_USED_ON_ENTITY_TRIGGER.get().trigger(curPlayer, player, Metal.CHROMIUM, true);
if (!Emotional.hasTinFoilHat(player)) {
wipePlayer(player);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.legobmw99.allomancy.modules.powers.util;

import com.legobmw99.allomancy.api.data.IAllomancerData;
import com.legobmw99.allomancy.api.enums.Metal;
import com.legobmw99.allomancy.modules.extras.ExtrasSetup;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -28,6 +30,9 @@ public static void speedUpNearby(ServerPlayer curPlayer, ServerLevel level, IAll
level
.getEntitiesOfClass(LivingEntity.class, AABB.encapsulatingFullBlocks(negative, positive))
.forEach(entity -> {
ExtrasSetup.METAL_USED_ON_ENTITY_TRIGGER
.get()
.trigger(curPlayer, entity, Metal.BENDALLOY, data.isEnhanced());
entity.aiStep();
entity.aiStep();
});
Expand Down Expand Up @@ -60,6 +65,9 @@ public static void slowDownNearby(ServerPlayer curPlayer, ServerLevel level, IAl
Vec3 positive = curPlayer.position().add(max, max, max);
int slowness_amplifier = data.isEnhanced() ? 255 : 2; // Duralumin freezes entities
level.getEntitiesOfClass(LivingEntity.class, new AABB(negative, positive)).forEach(entity -> {
ExtrasSetup.METAL_USED_ON_ENTITY_TRIGGER
.get()
.trigger(curPlayer, entity, Metal.CADMIUM, data.isEnhanced());
entity.addEffect(new MobEffectInstance(MobEffects.SLOW_FALLING, 10, 0, true, false));
if (entity != curPlayer) {
entity.addEffect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package com.legobmw99.allomancy.test.modules.combat;

import com.legobmw99.allomancy.Allomancy;
import com.legobmw99.allomancy.api.enums.Metal;
import com.legobmw99.allomancy.modules.combat.CombatSetup;
import com.legobmw99.allomancy.modules.materials.MaterialsSetup;
import com.legobmw99.allomancy.modules.powers.data.AllomancerAttachment;
import com.legobmw99.allomancy.test.util.AllomancyTestHelper;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.neoforged.testframework.annotation.ForEachTest;
import net.neoforged.testframework.annotation.TestHolder;
import net.neoforged.testframework.gametest.EmptyTemplate;

import java.util.Set;

@ForEachTest(groups = "items")

@ForEachTest(groups = "item")
public class CoinBagTest {

@GameTest
Expand Down Expand Up @@ -44,6 +47,41 @@ public static void coinBagShoots(AllomancyTestHelper helper) {
.thenSucceed();
}

@GameTest
@EmptyTemplate
@TestHolder(description = "Tests that the coin bag can shoot to kill")
public static void coinBagKills(AllomancyTestHelper helper) {
var player = helper.makeMistbornPlayer();
player.preventItemPickup();
var data = player.getData(AllomancerAttachment.ALLOMANCY_DATA);
data.setBurning(Metal.STEEL, true);

var nugget = MaterialsSetup.NUGGETS.get(Metal.CADMIUM.getIndex()).get();
player.setItemInHand(InteractionHand.OFF_HAND, new ItemStack(nugget, 1));

var chicken = helper.spawnWithNoFreeWill(EntityType.CHICKEN, BlockPos.ZERO);
helper.withLowHealth(chicken);

player.lookAt(EntityAnchorArgument.Anchor.EYES, chicken.position());

helper
.startSequence()
.thenMap(() -> helper.useItem(player, CombatSetup.COIN_BAG))
.thenExecute(res -> helper.assertTrue(res instanceof InteractionResult.Success, "failed to fire"))
.thenExecute(() -> {
helper.assertFalse(player.getInventory().hasAnyOf(Set.of(nugget)), "Player didn't spend ammo");
helper.assertFalse(helper.getEntities(CombatSetup.NUGGET_PROJECTILE.get()).isEmpty(),
"Didn't spawn coin");
})
.thenExecuteAfter(1, () -> {
helper.assertEntityNotPresent(EntityType.CHICKEN);
})
.thenExecuteAfter(2, () -> {
helper.assertItemEntityNotPresent(nugget);
helper.assertPlayerHasAdvancement(player, Allomancy.rl("main/coinshot"));
})
.thenSucceed();
}

@GameTest
@EmptyTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.neoforged.testframework.annotation.TestHolder;
import net.neoforged.testframework.gametest.EmptyTemplate;

@ForEachTest(groups = "items")
@ForEachTest(groups = "item")
public class KolossBladeTest {

@GameTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.legobmw99.allomancy.test.modules.consumables;

import com.legobmw99.allomancy.Allomancy;
import com.legobmw99.allomancy.api.enums.Metal;
import com.legobmw99.allomancy.modules.consumables.ConsumeSetup;
import com.legobmw99.allomancy.modules.consumables.item.VialItem;
Expand Down Expand Up @@ -38,6 +39,7 @@ public static void lerasiumMakesMistborn(AllomancyTestHelper helper) {
"Player never got invested");
helper.assertFalse(helper.getEntities(EntityType.LIGHTNING_BOLT).isEmpty(),
"Didn't spawn lightning");
helper.assertPlayerHasAdvancement(player, Allomancy.rl("main/become_mistborn"));
})
.thenIdle(4)
.thenSucceed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

// for automation, this class is done in a more vanilla GameTest style.
@GameTestHolder(AllomancyTest.MODID)
public class GrinderCraftingTest {

@RegisterStructureTemplate(AllomancyTest.MODID + ":crafter")
Expand Down Expand Up @@ -62,7 +60,7 @@ public static void register(Consumer<Test> add) {
var damagedGrinder = barrel.getItem(1).getDamageValue() == 1;
return craftedFlake && retainedGrinder && damagedGrinder;
}, () -> "Failed to craft flakes", ConsumeSetup.ALLOMANTIC_GRINDER, ingot);
}, structureName, "crafting", "Tests that " + metal +
}, structureName, "item", "Tests that " + metal +
" flake crafting works and the grinder is maintained"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.neoforged.testframework.annotation.TestHolder;
import net.neoforged.testframework.gametest.EmptyTemplate;

@ForEachTest(groups = "crafting")
@ForEachTest(groups = "item")
public class VialCraftingTest {

@GameTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import net.neoforged.testframework.gametest.EmptyTemplate;
import net.neoforged.testframework.gametest.ExtendedGameTestHelper;

@ForEachTest(groups = "blocks")
@ForEachTest(groups = "block")
public class BlocksTest {


Expand Down
Loading

0 comments on commit 74a76b5

Please sign in to comment.