Allow multiplying entity health by factor

This commit is contained in:
Johannes Frohnmeyer 2021-12-30 15:51:43 +01:00
parent fa18139a82
commit c9ec990770
Signed by: Johannes
GPG Key ID: E76429612C2929F4
9 changed files with 52 additions and 15 deletions

View File

@ -8,4 +8,4 @@ maven_group=io.gitlab.jfronny
archives_base_name=combit archives_base_name=combit
fabric_version=0.45.0+1.18 fabric_version=0.45.0+1.18
jfapi_version=2.2.0 jfapi_version=2.2.1

View File

@ -64,10 +64,13 @@ public class Combit implements ModInitializer {
if (player.getEntityWorld().isClient) if (player.getEntityWorld().isClient)
return ActionResult.PASS; return ActionResult.PASS;
if (CombitConfig.debug) if (CombitConfig.debug) {
player.sendMessage(new LiteralText( player.sendMessage(new LiteralText(
String.format("Entity attacked: %s", EntityType.getId(target.getType())) target instanceof LivingEntity le
? String.format("LivingEntity attacked: %s (%s/%s)", EntityType.getId(target.getType()), le.getHealth(), le.getMaxHealth())
: String.format("Entity attacked: %s", EntityType.getId(target.getType()))
), false); ), false);
}
float str = player.getAttackCooldownProgress(0); float str = player.getAttackCooldownProgress(0);
if (str <= CombitConfig.attackCancelThreshold) if (str <= CombitConfig.attackCancelThreshold)
@ -79,11 +82,10 @@ public class Combit implements ModInitializer {
}); });
} }
private String getId(Entity entity) { public static String getId(Entity entity) {
return EntityType.getId(entity.getType()).toString(); return EntityType.getId(entity.getType()).toString();
} }
public static boolean idMatches(String entityId, Set<String> matches) {
private boolean idMatches(String entityId, Set<String> matches) {
for (String id : matches) { for (String id : matches) {
int starIndex = id.indexOf('*'); int starIndex = id.indexOf('*');
if (starIndex != -1) { if (starIndex != -1) {

View File

@ -16,10 +16,14 @@ public class CombitConfig implements JfConfig {
@Entry public static HashSet<String> targetEntityWhitelist = null; @Entry public static HashSet<String> targetEntityWhitelist = null;
@Entry public static Boolean excludeAllMobs = false; @Entry public static Boolean excludeAllMobs = false;
@Entry public static Boolean excludePlayers = false; @Entry public static Boolean excludePlayers = false;
// Fluff // Health
@Entry public static Double entityHealthFactor = 1.5;
@Entry public static HashSet<String> entityHealthBlacklist = null;
// Weapons
@Entry public static Double cooldownProgressOverride = 0.8; @Entry public static Double cooldownProgressOverride = 0.8;
@Entry public static Double cooldownProgressPerTickOverride = Double.MIN_VALUE; @Entry public static Double cooldownProgressPerTickOverride = Double.MIN_VALUE;
@Entry public static Double weaponAttackDamageFactor = 0.6; @Entry public static Double weaponAttackDamageFactor = 0.6;
@Entry public static Double axeAttackDamageFactor = 0.5; @Entry public static Double axeAttackDamageFactor = 0.5;
// Debug
@Entry public static Boolean debug = FabricLoader.getInstance().isDevelopmentEnvironment(); @Entry public static Boolean debug = FabricLoader.getInstance().isDevelopmentEnvironment();
} }

View File

@ -33,6 +33,11 @@ public class CombitConfigValidator implements UltraEarlyInit {
CombitConfig.damageSourceWhitelist.add(DamageSource.OUT_OF_WORLD.getName()); CombitConfig.damageSourceWhitelist.add(DamageSource.OUT_OF_WORLD.getName());
CombitConfig.damageSourceWhitelist.add(DamageSource.SWEET_BERRY_BUSH.getName()); CombitConfig.damageSourceWhitelist.add(DamageSource.SWEET_BERRY_BUSH.getName());
} }
if (CombitConfig.entityHealthBlacklist == null) {
changed = true;
CombitConfig.entityHealthBlacklist = new HashSet<>();
CombitConfig.entityHealthBlacklist.add("minecraft:player");
}
if (changed) { if (changed) {
ConfigHolder.getInstance().getRegistered().get("combit").write(); ConfigHolder.getInstance().getRegistered().get("combit").write();
} }

View File

@ -1,17 +1,30 @@
package io.gitlab.jfronny.combit.mixin; package io.gitlab.jfronny.combit.mixin;
import io.gitlab.jfronny.combit.Combit;
import io.gitlab.jfronny.combit.CombitConfig;
import io.gitlab.jfronny.combit.events.EntityHurtEvent; import io.gitlab.jfronny.combit.events.EntityHurtEvent;
import io.gitlab.jfronny.combit.events.EntityKnockbackEvent; import io.gitlab.jfronny.combit.events.EntityKnockbackEvent;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.DamageSource;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(LivingEntity.class) @Mixin(LivingEntity.class)
public class LivingEntityMixin { public abstract class LivingEntityMixin {
@Shadow public abstract float getMaxHealth();
@Shadow public abstract void setHealth(float health);
@Shadow @Nullable public abstract EntityAttributeInstance getAttributeInstance(EntityAttribute attribute);
@Inject(at = @At("TAIL"), method = "applyDamage", cancellable = true) @Inject(at = @At("TAIL"), method = "applyDamage", cancellable = true)
private void onEntityHurt(final DamageSource source, final float amount, CallbackInfo ci) { private void onEntityHurt(final DamageSource source, final float amount, CallbackInfo ci) {
ActionResult result = EntityHurtEvent.EVENT.invoker().hurtEntity((LivingEntity) (Object) this, source, amount); ActionResult result = EntityHurtEvent.EVENT.invoker().hurtEntity((LivingEntity) (Object) this, source, amount);
@ -27,4 +40,14 @@ public class LivingEntityMixin {
ci.cancel(); ci.cancel();
} }
} }
@Inject(at = @At("RETURN"), method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V")
private void injectMaxHealth(EntityType<?> entityType, World world, CallbackInfo ci) {
if (!Combit.idMatches(EntityType.getId(entityType).toString(), CombitConfig.entityHealthBlacklist)) {
EntityAttributeInstance att = getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH);
att.setBaseValue(att.getBaseValue() * CombitConfig.entityHealthFactor);
setHealth(getMaxHealth());
}
else System.out.println("Skipping " + EntityType.getId(entityType).toString());
}
} }

View File

@ -18,18 +18,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MiningToolItem.class) @Mixin(MiningToolItem.class)
public abstract class MiningToolItemMixin extends ToolItem { public abstract class MiningToolItemMixin extends ToolItem {
@Mutable @Shadow @Final @Mutable private Multimap<EntityAttribute, EntityAttributeModifier> attributeModifiers;
@Shadow @Final private Multimap<EntityAttribute, EntityAttributeModifier> attributeModifiers; @Shadow @Final @Mutable private float attackDamage;
@Mutable
@Shadow @Final private float attackDamage;
public MiningToolItemMixin(ToolMaterial material, Settings settings) { public MiningToolItemMixin(ToolMaterial material, Settings settings) {
super(material, settings); super(material, settings);
} }
@Inject(at = @At("RETURN"), method = "<init>(FFLnet/minecraft/item/ToolMaterial;Lnet/minecraft/tag/Tag;Lnet/minecraft/item/Item$Settings;)V") @Inject(at = @At("RETURN"), method = "<init>(FFLnet/minecraft/item/ToolMaterial;Lnet/minecraft/tag/Tag;Lnet/minecraft/item/Item$Settings;)V")
private void modifyAttackDamage(float attackDamage, float attackSpeed, ToolMaterial material, Tag effectiveBlocks, Settings settings, CallbackInfo ci) { private void modifyAttackDamage(float attackDamage, float attackSpeed, ToolMaterial material, Tag<?> effectiveBlocks, Settings settings, CallbackInfo ci) {
double factor = ((MiningToolItem)(Object)this) instanceof AxeItem ? CombitConfig.axeAttackDamageFactor : CombitConfig.weaponAttackDamageFactor; double factor = ((MiningToolItem)(Object)this) instanceof AxeItem ? CombitConfig.axeAttackDamageFactor : CombitConfig.weaponAttackDamageFactor;
if (factor >= 0) { if (factor >= 0) {
this.attackDamage *= factor; this.attackDamage *= factor;

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

View File

@ -18,6 +18,11 @@
"combit.jfconfig.excludePlayers": "Exclude Players", "combit.jfconfig.excludePlayers": "Exclude Players",
"combit.jfconfig.excludePlayers.tooltip": "Still apply I-Frames to players", "combit.jfconfig.excludePlayers.tooltip": "Still apply I-Frames to players",
"combit.jfconfig.entityHealthFactor": "Entity Health Factor",
"combit.jfconfig.entityHealthFactor.tooltip": "Factor to apply to the maximum health of entities",
"combit.jfconfig.entityHealthBlacklist": "Entity Health Blacklist",
"combit.jfconfig.entityHealthBlacklist.tooltip": "Entities which should retain their original health (configure in JSON)",
"combit.jfconfig.cooldownProgressOverride": "Cooldown Progress Override", "combit.jfconfig.cooldownProgressOverride": "Cooldown Progress Override",
"combit.jfconfig.cooldownProgressOverride.tooltip": "Always set the cooldown of items to this value (negative to disable override)", "combit.jfconfig.cooldownProgressOverride.tooltip": "Always set the cooldown of items to this value (negative to disable override)",
"combit.jfconfig.cooldownProgressPerTickOverride": "Cooldown Progress/Tick Override", "combit.jfconfig.cooldownProgressPerTickOverride": "Cooldown Progress/Tick Override",
@ -26,6 +31,7 @@
"combit.jfconfig.weaponAttackDamageFactor.tooltip": "Factor to multiply to the attack damage of weapons except axes", "combit.jfconfig.weaponAttackDamageFactor.tooltip": "Factor to multiply to the attack damage of weapons except axes",
"combit.jfconfig.axeAttackDamageFactor": "Axe Attack Damage Factor", "combit.jfconfig.axeAttackDamageFactor": "Axe Attack Damage Factor",
"combit.jfconfig.axeAttackDamageFactor.tooltip": "Factor to multiply to the attack damage of axes", "combit.jfconfig.axeAttackDamageFactor.tooltip": "Factor to multiply to the attack damage of axes",
"combit.jfconfig.debug": "Debug", "combit.jfconfig.debug": "Debug",
"combit.jfconfig.debug.tooltip": "Enable Debug Logging" "combit.jfconfig.debug.tooltip": "Enable Debug Logging"
} }

View File

@ -2,7 +2,7 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "io.gitlab.jfronny.combit.mixin", "package": "io.gitlab.jfronny.combit.mixin",
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_17",
"mixins": [ "mixins": [
"LivingEntityMixin", "LivingEntityMixin",
"MiningToolItemMixin", "MiningToolItemMixin",