Skip to content

Commit

Permalink
Rework config / add presets
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jun 27, 2024
1 parent 3b16bb1 commit f6723d9
Show file tree
Hide file tree
Showing 13 changed files with 471 additions and 298 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ It can also display multiple particles with different setting for same damage, a

# Configuration.
This mod config file is stored as `./config/ouch.json`.
## Preset selection config.
By default, config is in a format of preset selection, allowing you to choose default style/look that's built into the mod.
```json5
{
"preset": "default"
}
```
Available presets: `default`, `minimal`
## Full config.
This config allows you to change any text and it's behaviour. Can be used for advanced configuration.
Default values used by presets can be found here: https://github.com/Patbox/ouch/tree/master/preset
All custom text within it uses the [QuickText format](https://placeholders.pb4.eu/user/quicktext/).
All predicates use are supplied by [Predicate API, using this format](https://github.com/Patbox/PredicateAPI/blob/1.21/BUILTIN.md).
Lines prefixed with `//` aren't part of real config and are here just to explain it.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.parallel=true
loader_version=0.15.11

# Mod Properties
mod_version = 1.0.1
mod_version = 1.1.0
maven_group = eu.pb4
archives_base_name = ouch

Expand Down
139 changes: 139 additions & 0 deletions preset/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"damage": [
[
{
"text": "<#ff0000>-${value}</><yellow>☀",
"type": "minecraft:dry_out"
},
{
"text": "<#ff0000>-${value}</><aqua>🔱",
"type": "minecraft:trident"
},
{
"text": "<#ff0000>-${value}</><gray>☃",
"type": "minecraft:bad_respawn_point"
},
{
"text": "<#ff0000>-${value}</><dark_gray>🍖",
"type": "minecraft:starve"
},
{
"text": "<#ff0000>-${value}</><aqua>🔱",
"type": "minecraft:trident"
},
{
"text": "<#ff0000>-${value}</><red>♦",
"type": "minecraft:cramming"
},
{
"text": "<#ff0000>-${value}</><gray>☄",
"type": "minecraft:fall"
},
{
"text": "<#ff0000>-${value}</><yellow>☄",
"type": "minecraft:fly_into_wall"
},
{
"text": "<#ff0000>-${value}</><gray>▒",
"type": "minecraft:in_wall"
},
{
"text": "<#ff0000>-${value}</><dark_aqua>☀",
"type": "minecraft:sonic_boom"
},
{
"text": "<#ff0000>-${value}</><white>☄",
"type": "minecraft:spit"
},
{
"text": "<#ff0000>-${value}</><yellow>▽",
"type": "minecraft:sting"
},
{
"text": "<#ff0000>-${value}</><yellow>△",
"type": "minecraft:thorns"
},
{
"text": "<#ff0000>-${value}</><light_gray>🗡",
"type": [
"minecraft:mob_attack",
"minecraft:player_attack",
"minecraft:mob_attack_no_aggro"
]
},
{
"text": "<#ff0000>-${value}</><yellow>⚠",
"type": [
"minecraft:out_of_world",
"minecraft:outside_border"
]
},
{
"text": "<#ff0000>-${value}</><purple>🧪",
"type": [
"minecraft:magic",
"minecraft:indirect_magic",
"minecraft:dragon_breath"
]
},
{
"text": "<#ff0000>-${value}</><dark_gray>🧪",
"type": [
"minecraft:wither",
"minecraft:wither_skull"
]
},
{
"text": "<#ff0000>-${value}</><dark_green>♦",
"type": [
"minecraft:cactus",
"minecraft:sweet_berry_bush"
]
},
{
"text": "<#ff0000>-${value}</><red>☄",
"type": [
"minecraft:falling_stalactite",
"minecraft:falling_anvil",
"minecraft:falling_block"
]
},
{
"text": "<#ff0000>-${value}</><orange>🔥",
"type": "#minecraft:is_fire"
},
{
"text": "<#ff0000>-${value}</><white>☀",
"type": "#minecraft:is_explosion"
},
{
"text": "<#ff0000>-${value}</><yellow>🏹",
"type": "#minecraft:is_projectile"
},
{
"text": "<#ff0000>-${value}</><blue>🌊",
"type": "#minecraft:is_drowning"
},
{
"text": "<#ff0000>-${value}</><white>❄",
"type": "#minecraft:is_freezing"
},
{
"text": "<#ff0000>-${value}</><yellow>⚡",
"type": "#minecraft:is_lightning"
},
{
"text": "<#ff0000>-${value}</>",
"type": []
}
]
],
"healing": [
[
{
"text": "<#00FF00>+${value}"
}
]
],
"death": []
}
18 changes: 18 additions & 0 deletions preset/minimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"damage": [
[
{
"text": "<#ff0000>-${value}</>",
"type": []
}
]
],
"healing": [
[
{
"text": "<#00FF00>+${value}"
}
]
],
"death": []
}
50 changes: 24 additions & 26 deletions src/main/java/eu/pb4/ouch/DamageDisplayLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import eu.pb4.ouch.api.DefaultDisplayEvents;
import eu.pb4.placeholders.api.ParserContext;
import eu.pb4.placeholders.api.PlaceholderContext;
import eu.pb4.placeholders.api.parsers.NodeParser;
Expand All @@ -24,7 +23,7 @@
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;

import java.util.List;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
Expand Down Expand Up @@ -76,39 +75,29 @@ public static DamageDisplayLogic of(float chance, MinecraftPredicate predicate,
);
}

public static DamageDisplayLogic of(RegistryWrapper.WrapperLookup wrapper, RegistryKey<DamageType> type, String format) {
return new DamageDisplayLogic(Optional.of(RegistryEntryList.of(wrapper.getWrapperOrThrow(RegistryKeys.DAMAGE_TYPE).getOrThrow(type))),
BuiltinPredicates.alwaysTrue(),
BuiltinPredicates.alwaysTrue(),
BuiltinPredicates.alwaysTrue(),
1,
WrappedText.from(PARSER, DefaultDisplayEvents.MODIFY_DISPLAY_LOGIC.invoker().modify(wrapper, List.of(type), format)),
FloatingText.DisplaySettings.GENERAL
);
}
public static DamageDisplayLogic of(RegistryWrapper.WrapperLookup wrapper, List<RegistryKey<DamageType>> type, String format) {
return new DamageDisplayLogic(Optional.of(RegistryEntryList.of(type.stream().map(wrapper.getWrapperOrThrow(RegistryKeys.DAMAGE_TYPE)::getOrThrow).toList())),
BuiltinPredicates.alwaysTrue(),
BuiltinPredicates.alwaysTrue(),
BuiltinPredicates.alwaysTrue(),
1,
WrappedText.from(PARSER, DefaultDisplayEvents.MODIFY_DISPLAY_LOGIC.invoker().modify(wrapper, type, format)),
public static DamageDisplayLogic of(RegistryWrapper.WrapperLookup wrapper, String format, float chance, MinecraftPredicate victimPredicate, MinecraftPredicate sourcePredicate, MinecraftPredicate attackerPredicate, RegistryKey<DamageType>... type) {
var x = wrapper.getWrapperOrThrow(RegistryKeys.DAMAGE_TYPE);
return new DamageDisplayLogic(Optional.of(RegistryEntryList.of(Arrays.stream(type).map(x::getOrThrow).toList())),
victimPredicate,
attackerPredicate,
sourcePredicate,
chance,
WrappedText.from(PARSER, format),
FloatingText.DisplaySettings.GENERAL
);
}

public static DamageDisplayLogic of(RegistryWrapper.WrapperLookup wrapper, TagKey<DamageType> tag, String format) {
public static DamageDisplayLogic of(RegistryWrapper.WrapperLookup wrapper, String format, float chance, MinecraftPredicate victimPredicate, MinecraftPredicate sourcePredicate, MinecraftPredicate attackerPredicate, TagKey<DamageType> tag) {
return new DamageDisplayLogic(Optional.of(wrapper.getWrapperOrThrow(RegistryKeys.DAMAGE_TYPE).getOrThrow(tag)),
BuiltinPredicates.alwaysTrue(),
BuiltinPredicates.alwaysTrue(),
BuiltinPredicates.alwaysTrue(),
1,
victimPredicate,
attackerPredicate,
sourcePredicate,
chance,
WrappedText.from(PARSER, format),
FloatingText.DisplaySettings.GENERAL
);
}

public void provide(LivingEntity entity, DamageSource source, float amount, BiConsumer<Text, FloatingText.DisplaySettings> consumer) {
public void provideDamage(LivingEntity entity, DamageSource source, float amount, BiConsumer<Text, FloatingText.DisplaySettings> consumer) {
consumer.accept(this.text.textNode().toText(PlaceholderContext.of(entity).asParserContext().with(PLACEHOLDER_KEY, key -> switch (key) {
case "value" -> Text.literal(MathHelper.floor(amount) + "." + (MathHelper.floor(amount * 10) % 10));
case "value_rounded" -> Text.literal("" + Math.round(amount));
Expand All @@ -117,6 +106,15 @@ public void provide(LivingEntity entity, DamageSource source, float amount, BiCo
})), this.displaySettings);
}

public void provideDeath(LivingEntity entity, DamageSource source, BiConsumer<Text, FloatingText.DisplaySettings> consumer) {
consumer.accept(this.text.textNode().toText(PlaceholderContext.of(entity).asParserContext().with(PLACEHOLDER_KEY, key -> switch (key) {
case "message" -> source.getDeathMessage(entity);
case "victim" -> entity.getDisplayName();
case "attacker" -> source.getAttacker() != null ? source.getAttacker().getDisplayName() : Text.empty();
case null, default -> Text.empty();
})), this.displaySettings);
}

public boolean match(LivingEntity entity, DamageSource source, PredicateContext predicateContext, PredicateContext attackerContext, PredicateContext sourceContext) {
return (this.type.isEmpty() || this.type.get().contains(source.getTypeRegistryEntry()))
&& this.victimPredicate.test(predicateContext).success()
Expand Down
110 changes: 0 additions & 110 deletions src/main/java/eu/pb4/ouch/DeathDisplayLogic.java

This file was deleted.

Loading

0 comments on commit f6723d9

Please sign in to comment.