Skip to content

Commit 05784bc

Browse files
committed
Add configurable entity relations (by arbitrary entity id)
1 parent fec0e8f commit 05784bc

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 1.7.3
22

3+
- Add configurable entity relations (by arbitrary entity id). Iron Golem and Guard Villagers included by default as neutral.
34
- Add barebone attack range modification API
45
- Disable idle animations while swimming
56
- Fix default configs for Farmer's Delight items (delete `config/bettercombat` folder to reset your configs)

common/src/main/java/net/bettercombat/config/ServerConfig.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment;
66
import net.bettercombat.logic.TargetHelper;
77

8+
import java.util.Map;
9+
810
@Config(name = "server")
911
public class ServerConfig implements ConfigData {
1012
@Comment("""
@@ -71,12 +73,34 @@ Entities struck (+1) in a swing more than this, won't get weakened any further.
7173
public float dual_wielding_main_hand_damage_multiplier = 1F;
7274
@Comment("Total multiplier, (examples: +30% = 1.3, -30% = 0.7)")
7375
public float dual_wielding_off_hand_damage_multiplier = 1F;
74-
@Comment("Entities with `HOSTILE` relation will be hit by undirected weapon swings. NOTE: Vanilla sweeping will still happen, if not disabled via `allow_sweeping`")
75-
public TargetHelper.Relation player_relation_to_teamless_players = TargetHelper.Relation.NEUTRAL;
76-
public TargetHelper.Relation player_relation_to_villagers = TargetHelper.Relation.NEUTRAL;
76+
77+
@Comment("""
78+
Relations determine when players' undirected weapon swings (cleaves) will hurt another entity (target).
79+
- `FRIENDLY` - The target can never be damaged by the player.
80+
- `NEUTRAL` - The target can be damaged only if the player is directly looking at it.
81+
- `HOSTILE` - The target can be damaged if located within the weapon swing area.
82+
(NOTE: Vanilla sweeping can still hit targets, if not disabled via `allow_sweeping`)
83+
84+
The various relation related configs are being checked in the following order:
85+
- `player_relations`
86+
- `player_relation_to_passives`
87+
- `player_relation_to_hostiles`
88+
- `player_relation_to_other`
89+
(The first relation to be found for the target will be applied.)
90+
""")
91+
public Map<String, TargetHelper.Relation> player_relations = Map.of(
92+
"minecraft:player", TargetHelper.Relation.NEUTRAL,
93+
"minecraft:villager", TargetHelper.Relation.NEUTRAL,
94+
"minecraft:iron_golem", TargetHelper.Relation.NEUTRAL,
95+
"guardvillagers:guard", TargetHelper.Relation.NEUTRAL
96+
);
97+
@Comment("Relation to unspecified entities those are instance of PassiveEntity(Yarn)")
7798
public TargetHelper.Relation player_relation_to_passives = TargetHelper.Relation.HOSTILE;
99+
@Comment("Relation to unspecified entities those are instance of HostileEntity(Yarn)")
78100
public TargetHelper.Relation player_relation_to_hostiles = TargetHelper.Relation.HOSTILE;
101+
@Comment("Fallback relation")
79102
public TargetHelper.Relation player_relation_to_other = TargetHelper.Relation.HOSTILE;
103+
80104
@Comment("Try to guess and apply a preset for items without weapon attributes data file")
81105
public boolean fallback_compatibility_enabled = true;
82106
@Comment("Allow printing the content of weapon attributes registry")

common/src/main/java/net/bettercombat/logic/TargetHelper.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import net.minecraft.entity.decoration.AbstractDecorationEntity;
77
import net.minecraft.entity.mob.HostileEntity;
88
import net.minecraft.entity.passive.PassiveEntity;
9-
import net.minecraft.entity.passive.VillagerEntity;
109
import net.minecraft.entity.player.PlayerEntity;
10+
import net.minecraft.registry.Registries;
1111

1212
import java.util.Arrays;
1313

@@ -40,11 +40,10 @@ public static Relation getRelation(PlayerEntity attacker, Entity target) {
4040
var casterTeam = attacker.getScoreboardTeam();
4141
var targetTeam = target.getScoreboardTeam();
4242
if (casterTeam == null || targetTeam == null) {
43-
if (target instanceof PlayerEntity) {
44-
return Relation.coalesce(config.player_relation_to_teamless_players, Relation.NEUTRAL);
45-
}
46-
if (target instanceof VillagerEntity) {
47-
return Relation.coalesce(config.player_relation_to_villagers, Relation.NEUTRAL);
43+
var id = Registries.ENTITY_TYPE.getId(target.getType());
44+
var mappedRelation = config.player_relations.get(id.toString());
45+
if (mappedRelation != null) {
46+
return mappedRelation;
4847
}
4948
if (target instanceof PassiveEntity) {
5049
return Relation.coalesce(config.player_relation_to_passives, Relation.HOSTILE);

0 commit comments

Comments
 (0)