Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pop context changes #1182

Open
wants to merge 10 commits into
base: demo-pop-context
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2023-10-08T20:36:02.3108508 Ars Nouveau Item Models
// 1.20.1 2023-12-07T14:41:19.63697 Ars Nouveau Item Models
11ee554b11a3a830e89b742762e5b754c2ecb5ee assets/ars_nouveau/models/item/agronomic_sourcelink.json
339a05323ebef7efc5c70db708a2e7a24708e9bc assets/ars_nouveau/models/item/alchemical_sourcelink.json
a0214090201827dd5f954d0b33e64e4df6e53764 assets/ars_nouveau/models/item/alchemists_crown.json
Expand All @@ -8,6 +8,9 @@ f9eb0905e283cab647712716770a244a1bdb25f0 assets/ars_nouveau/models/item/bastion_
a81ea25c1312389ff436100c29d1ae20d35b0a40 assets/ars_nouveau/models/item/blue_sbed.json
3b7dc3023a667efe5ff64cb937ee25047a853697 assets/ars_nouveau/models/item/bombegranate_pod.json
57a68c0d674b3622478b1b83f8543be58f6e3018 assets/ars_nouveau/models/item/burst.json
03abae333f96a718145e735c60e08811816b7710 assets/ars_nouveau/models/item/else.json
ba117deb89db256ad35166da404db90173050f77 assets/ars_nouveau/models/item/escape_context.json
35ff8255464dc12598ca358923ef4894c0a8d0da assets/ars_nouveau/models/item/example_filter.json
23781f068b9b788d0077a478b0470af583d759f5 assets/ars_nouveau/models/item/experience_gem.json
70d392c53a05ad554f3f3b1d3faa5fd1445e2a77 assets/ars_nouveau/models/item/falseweave.json
5f620c31cc6d4f1a569dbd943e5a45e75217303a assets/ars_nouveau/models/item/familiar_amethyst_golem.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.1 2023-12-01T19:20:08.3250408 Languages: en_us
01c4d53fd9e1ab25a7930e77e28f61febdfc9844 assets/ars_nouveau/lang/en_us.json
// 1.20.1 2023-12-07T14:30:04.1509797 Languages: en_us
cb017f7e3b046f8d64d41b0b8fa195f24906aafc assets/ars_nouveau/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2023-12-01T22:20:29.6451076 Patchouli
// 1.20.1 2023-12-07T14:30:04.1479862 Patchouli
d5f03c259d2af4f5e8e286639783f4fc833b1076 assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/aqua_affinity.json
2ec536fea831588201432d61d70af61385882054 assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/armor/alteration_table.json
a82f4fc73946d228b1e3f5e03d0ecef46f33cdfb assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/armor/applying_perks.json
Expand Down Expand Up @@ -93,6 +93,9 @@ a09f89d0ec927fce49d1736c39305bcfeac052cf assets/ars_nouveau/patchouli_books/worn
81fcf49cd2e09ae38f0105066a60dd0c996a8146 assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/getting_started/trinkets.json
877210c24dbbaf4e365c30c8ba571cf2708e7d03 assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/getting_started/upgrades.json
521277fbf32424a30a8be24b137c786dc0b89cdc assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/getting_started/world_generation.json
536eeeef84dadd5a290deb061e5fa4f68beff18b assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/glyphs_1/else.json
d37c9395b15a762f56ab17cd0cf6d0ea3180b43a assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/glyphs_1/escape_context.json
165d1e4442670c262f7d23aed1c9bb8d9cee3958 assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/glyphs_1/example_filter.json
a80d0aabd3eff91451b0e80fb34514c5ce57eadf assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/glyphs_1/glyph_amplify.json
e6a01dcd171d462c0eb988478f64f994c63180f0 assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/glyphs_1/glyph_bounce.json
7d579e642d5c9a7c5dba516e1eadca7d87f9ad56 assets/ars_nouveau/patchouli_books/worn_notebook/en_us/entries/glyphs_1/glyph_break.json
Expand Down
12 changes: 12 additions & 0 deletions src/generated/resources/assets/ars_nouveau/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
"ars_nouveau.getting_started_desc": "An introduction to Ars Nouveau. It is recommended to follow each section in order.",
"ars_nouveau.glyph_crafting": "Glyph Crafting",
"ars_nouveau.glyph_desc.burst": "Resolves the spell in a spherical area around the target. Augment with Sensitive to target blocks instead of entities and Dampen to make an empty sphere. Augment with AOE to increase the radius. ",
"ars_nouveau.glyph_desc.else": "",
"ars_nouveau.glyph_desc.escape_context": "",
"ars_nouveau.glyph_desc.example_filter": "",
"ars_nouveau.glyph_desc.glyph_accelerate": "Increases the speed of projectile spells.",
"ars_nouveau.glyph_desc.glyph_amplify": "Additively increases the power of most spell effects. Can increase the harvest level of Break and increases the damage of spells.",
"ars_nouveau.glyph_desc.glyph_animate_block": "Animates a block to fight for you. The animated block will convert to a falling block when it dies. Costs a large amount of mana, but does not grant Summoning Sickness",
Expand Down Expand Up @@ -274,6 +277,9 @@
"ars_nouveau.glyph_desc.glyph_wind_shear": "Deals damage to targets in the air, with an increasing amount based on how high the target is off the ground, up to 10 blocks. Targets on the ground take no damage.",
"ars_nouveau.glyph_desc.glyph_wither": "Applies the Wither debuff.",
"ars_nouveau.glyph_name.burst": "Burst",
"ars_nouveau.glyph_name.else": "Else",
"ars_nouveau.glyph_name.escape_context": "Escape Context",
"ars_nouveau.glyph_name.example_filter": "Example Filter",
"ars_nouveau.glyph_name.glyph_accelerate": "Accelerate",
"ars_nouveau.glyph_name.glyph_amplify": "Amplify",
"ars_nouveau.glyph_name.glyph_animate_block": "Animate Block",
Expand Down Expand Up @@ -765,9 +771,12 @@
"ars_nouveau.spell.validation.adding.action_augmentation_policy": "%s is already augmented to the limit by %s.",
"ars_nouveau.spell.validation.adding.action_augmentation_policy.zero": "%s may not be augmented by %s.",
"ars_nouveau.spell.validation.adding.augment_compatibility": "%s cannot be augmented by %s",
"ars_nouveau.spell.validation.adding.empty_manipulation": "%s has no context to pop",
"ars_nouveau.spell.validation.adding.glyph_occurrences_policy": "%s has appeared its maximum number of times.",
"ars_nouveau.spell.validation.adding.glyph_tier": "%s is too powerful for your current spell book.",
"ars_nouveau.spell.validation.adding.invalid_combination_policy": "%s cannot be used with %s",
"ars_nouveau.spell.validation.adding.invalid_manipulation": "%s cannot pop %s",
"ars_nouveau.spell.validation.adding.invalid_nesting_policy": "%s cannot be nested with %s",
"ars_nouveau.spell.validation.adding.max_one_cast_method": "The spell already has a form glyph.",
"ars_nouveau.spell.validation.adding.non_empty_spell": "The spell may not be empty.",
"ars_nouveau.spell.validation.adding.starting_cast_method": "The spell must start with a form glyph.",
Expand All @@ -777,9 +786,12 @@
"ars_nouveau.spell.validation.exists.action_augmentation_policy": "%s was augmented by %s too many times.",
"ars_nouveau.spell.validation.exists.action_augmentation_policy.zero": "%s may not be augmented by %s.",
"ars_nouveau.spell.validation.exists.augment_compatibility": "%s cannot be augmented by %s",
"ars_nouveau.spell.validation.exists.empty_manipulation": "%s has no context to pop",
"ars_nouveau.spell.validation.exists.glyph_occurrences_policy": "%s appears too many times.",
"ars_nouveau.spell.validation.exists.glyph_tier": "%s is too powerful for your current spell book.",
"ars_nouveau.spell.validation.exists.invalid_combination_policy": "%s cannot be used with %s",
"ars_nouveau.spell.validation.exists.invalid_manipulation": "%s cannot pop %s",
"ars_nouveau.spell.validation.exists.invalid_nesting_policy": "%s cannot be nested with %s",
"ars_nouveau.spell.validation.exists.max_one_cast_method": "The spell has an extra form glyph: %s",
"ars_nouveau.spell.validation.exists.non_empty_spell": "The spell may not be empty.",
"ars_nouveau.spell.validation.exists.starting_cast_method": "The spell does not start with a form glyph.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "ars_nouveau:item/else"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "ars_nouveau:item/escape_context"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "ars_nouveau:item/example_filter"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category": "ars_nouveau:glyphs_1",
"icon": "ars_nouveau:else",
"name": "ars_nouveau.glyph_name.else",
"pages": [
{
"type": "patchouli:text",
"text": "ars_nouveau.glyph_desc.else"
},
{
"type": "ars_nouveau:glyph_recipe",
"recipe": "ars_nouveau:else"
}
],
"sortnum": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category": "ars_nouveau:glyphs_1",
"icon": "ars_nouveau:escape_context",
"name": "ars_nouveau.glyph_name.escape_context",
"pages": [
{
"type": "patchouli:text",
"text": "ars_nouveau.glyph_desc.escape_context"
},
{
"type": "ars_nouveau:glyph_recipe",
"recipe": "ars_nouveau:escape_context"
}
],
"sortnum": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category": "ars_nouveau:glyphs_1",
"icon": "ars_nouveau:example_filter",
"name": "ars_nouveau.glyph_name.example_filter",
"pages": [
{
"type": "patchouli:text",
"text": "ars_nouveau.glyph_desc.example_filter"
},
{
"type": "ars_nouveau:glyph_recipe",
"recipe": "ars_nouveau:example_filter"
}
],
"sortnum": 2
}
12 changes: 12 additions & 0 deletions src/main/java/com/hollingsworth/arsnouveau/api/ArsNouveauAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.hollingsworth.arsnouveau.api.enchanting_apparatus.IEnchantingRecipe;
import com.hollingsworth.arsnouveau.api.recipe.PotionIngredient;
import com.hollingsworth.arsnouveau.api.scrying.IScryer;
import com.hollingsworth.arsnouveau.api.spell.AbstractEffect;
import com.hollingsworth.arsnouveau.api.spell.AbstractSpellPart;
import com.hollingsworth.arsnouveau.api.spell.ISpellValidator;
import com.hollingsworth.arsnouveau.common.mixin.PotionRecipeMixin;
import com.hollingsworth.arsnouveau.common.spell.validation.StandardSpellValidator;
Expand Down Expand Up @@ -57,6 +59,16 @@ public Set<RecipeType<? extends IEnchantingRecipe>> getEnchantingRecipeTypes() {
return enchantingRecipeTypes;
}

private static ConcurrentHashMap.KeySetView<AbstractEffect, Boolean> contextCreators = ConcurrentHashMap.newKeySet();

public static void RegisterContextCreator(AbstractEffect context){
contextCreators.add(context);
}

public static boolean IsContextCreator(AbstractSpellPart part){
return part instanceof AbstractEffect effect ? contextCreators.contains(effect) : false;
}


public List<IEnchantingRecipe> getEnchantingApparatusRecipes(Level world) {
List<IEnchantingRecipe> recipes = new ArrayList<>(enchantingApparatusRecipes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void buildConfig(ForgeConfigSpec.Builder builder) {
buildAugmentCostOverrideConfig(builder, defaultAugmentCosts);
super.buildAugmentLimitsConfig(builder, getDefaultAugmentLimits(new HashMap<>()));
super.buildInvalidCombosConfig(builder, getDefaultInvalidCombos(new HashSet<>()));
super.buildInvalidNestingsConfig(builder, getDefaultInvalidNestings(new HashSet<>()));
}

public void addDamageConfig(ForgeConfigSpec.Builder builder, double defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.hollingsworth.arsnouveau.api.spell;

import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import org.apache.logging.log4j.core.LoggerContext;
import org.jetbrains.annotations.NotNull;

import java.util.Set;
Expand All @@ -29,15 +33,22 @@ protected Set<AbstractAugment> getCompatibleAugments() {
return Set.of();
}


@Override
public void onResolveEntity(EntityHitResult rayTraceResult, Level world, @NotNull LivingEntity shooter, SpellStats spellStats, SpellContext spellContext, SpellResolver resolver) {
if (!shouldResolveOnEntity(rayTraceResult, world)) spellContext.setCanceled(true);
boolean succeeded = shouldResolveOnEntity(rayTraceResult, world);
SpellContext newContext = spellContext.popContext(succeeded);
SpellResolver resolver1 = resolver.getNewResolver(newContext.clone().withParent(spellContext));
resolver1.previousResolver = resolver;
resolver1.onResolveEffect(world, rayTraceResult);
}

@Override
public void onResolveBlock(BlockHitResult rayTraceResult, Level world, @NotNull LivingEntity shooter, SpellStats spellStats, SpellContext spellContext, SpellResolver resolver) {
if (!shouldResolveOnBlock(rayTraceResult, world)) spellContext.setCanceled(true);
boolean succeeded = shouldResolveOnBlock(rayTraceResult, world);
SpellContext newContext = spellContext.popContext(succeeded);
SpellResolver resolver1 = resolver.getNewResolver(newContext);
resolver1.previousResolver = resolver;
resolver1.onResolveEffect(world, rayTraceResult);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public ResourceLocation getRegistryName() {
*/
public SpellPartConfigUtil.ComboLimits invalidCombinations = new SpellPartConfigUtil.ComboLimits(null);

/**
* A wrapper for the list of glyphs that cannot be used with this glyph. Parsed from configs.
*/
public SpellPartConfigUtil.ComboLimits invalidNestings = new SpellPartConfigUtil.ComboLimits(null);

public AbstractSpellPart(String registryName, String name) {
this(new ResourceLocation(ArsNouveau.MODID, registryName), name);
}
Expand Down Expand Up @@ -196,6 +201,10 @@ protected void buildInvalidCombosConfig(ForgeConfigSpec.Builder builder, Set<Res
this.invalidCombinations = SpellPartConfigUtil.buildInvalidCombosConfig(builder, defaults);
}

protected void buildInvalidNestingsConfig(ForgeConfigSpec.Builder builder, Set<ResourceLocation> defaults) {
this.invalidNestings = SpellPartConfigUtil.buildInvalidNestingsConfig(builder, defaults);
}

/**
* Override this method to provide defaults for the augmentation limits configuration.
*/
Expand All @@ -215,9 +224,14 @@ protected Set<ResourceLocation> getDefaultInvalidCombos(Set<ResourceLocation> de
addDefaultInvalidCombos(defaults);
return defaults;
}

protected Set<ResourceLocation> getDefaultInvalidNestings(Set<ResourceLocation> defaults) {
addDefaultInvalidNestings(defaults);
return defaults;
}
protected void addDefaultInvalidCombos(Set<ResourceLocation> defaults) {
}
protected void addDefaultInvalidNestings(Set<ResourceLocation> defaults) {
}

// Default value for the starter spell config
public boolean defaultedStarterGlyph() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.hollingsworth.arsnouveau.api.spell;

public interface IContextManipulator {


SpellContext manipulate(SpellContext context);
default boolean CanEscape(AbstractEffect effect){
return true;
}
SpellContext manipulate(SpellContext context, boolean filterSucceeded);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.hollingsworth.arsnouveau.api.spell;

import com.hollingsworth.arsnouveau.api.ANFakePlayer;
import com.hollingsworth.arsnouveau.api.ArsNouveauAPI;
import com.hollingsworth.arsnouveau.api.spell.wrapped_caster.IWrappedCaster;
import com.hollingsworth.arsnouveau.api.spell.wrapped_caster.LivingCaster;
import com.hollingsworth.arsnouveau.client.particle.ParticleColor;
import com.hollingsworth.arsnouveau.common.spell.validation.ContextSpellValidator;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.apache.logging.log4j.core.LoggerContext;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -86,19 +89,32 @@ public SpellContext withParent(SpellContext parent){
return part;
}

public SpellContext popContext(){
public SpellContext popContext(boolean filterPassed){
Spell remainder = getRemainingSpell();
int depth = 0;
for(AbstractSpellPart spellPart : remainder.recipe){
//check some escape contexts might be popping other contexts, not ours
if(ArsNouveauAPI.IsContextCreator(spellPart)){
depth +=1;
}
if(spellPart instanceof IContextManipulator manipulator){
SpellContext newContext = manipulator.manipulate(this);
if(newContext != null){
newContext.previousContext = this;
return newContext;
depth -=1;
//actually pop the current context
if(depth <= 0) {
SpellContext newContext = manipulator.manipulate(this, filterPassed);
if (newContext != null) {
newContext.previousContext = this;
return newContext;
}
}
}
}
setCanceled(true);
return this;
Spell newSpell = filterPassed ? this.getRemainingSpell() : this.getSpell().clone().setRecipe(new ArrayList<>());
SpellContext newContext = this.clone().withSpell(newSpell);
newContext.previousContext = this;
this.setCanceled(true);
return newContext;
}

public boolean hasNextPart() {
Expand Down Expand Up @@ -196,6 +212,12 @@ public SpellContext clone() {
clone.type = this.type;
clone.level = this.level;
clone.wrappedCaster = this.wrappedCaster;
/*
LoggerContext.getContext().getLogger(SpellContext.class).info("previous context:"+previousContext);
if(previousContext != null){
LoggerContext.getContext().getLogger(SpellContext.class).info("previous context spell:"+previousContext.getSpell().serialize().toString());
}
*/
clone.previousContext = this.previousContext == null ? null : this.previousContext.clone();
return clone;
} catch (CloneNotSupportedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ protected void addTranslations() {
add("ars_nouveau.spell.validation.exists.augment_compatibility", "%s cannot be augmented by %s");
add("ars_nouveau.spell.validation.exists.glyph_tier", "%s is too powerful for your current spell book.");
add("ars_nouveau.spell.validation.exists.invalid_combination_policy", "%s cannot be used with %s");
add("ars_nouveau.spell.validation.exists.invalid_nesting_policy", "%s cannot be nested with %s");
add("ars_nouveau.spell.validation.exists.empty_manipulation", "%s has no context to pop");
add("ars_nouveau.spell.validation.exists.invalid_manipulation", "%s cannot pop %s");
add("ars_nouveau.spell.validation.adding._comment", "__ These messages appear when attempting to add a glyph that would make a spell invalid. __");
add("ars_nouveau.spell.validation.adding.non_empty_spell", "The spell may not be empty.");
add("ars_nouveau.spell.validation.adding.max_one_cast_method", "The spell already has a form glyph.");
Expand All @@ -386,6 +389,9 @@ protected void addTranslations() {
add("ars_nouveau.spell.validation.adding.glyph_occurrences_policy", "%s has appeared its maximum number of times.");
add("ars_nouveau.spell.validation.adding.augment_compatibility", "%s cannot be augmented by %s");
add("ars_nouveau.spell.validation.adding.invalid_combination_policy", "%s cannot be used with %s");
add("ars_nouveau.spell.validation.adding.invalid_nesting_policy", "%s cannot be nested with %s");
add("ars_nouveau.spell.validation.adding.empty_manipulation", "%s has no context to pop");
add("ars_nouveau.spell.validation.adding.invalid_manipulation", "%s cannot pop %s");
add("ars_nouveau.spell.validation.adding.glyph_tier", "%s is too powerful for your current spell book.");
add("ars_nouveau.spell.no_mana", "Not enough Mana.");
add("block.ars_nouveau.potion_jar", "Potion Jar");
Expand Down
Loading