From b3190d5129b847dd1a581ba19d07d4486fac0d18 Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Tue, 9 May 2023 17:08:13 +0200 Subject: [PATCH] modify converter default values and add attribute check --- .../vampirism/config/BalanceMobProps.java | 3 +++ .../ConvertiblesReloadListener.java | 8 ++++---- .../entity/converted/ConvertedCowEntity.java | 8 +------- .../entity/converted/ConvertedSheepEntity.java | 7 +------ .../converted/VampirismEntityRegistry.java | 18 +++++++++++++++--- .../converted/converter/DefaultConverter.java | 8 +------- .../converted/converter/SpecialConverter.java | 7 +++---- 7 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/main/java/de/teamlapen/vampirism/config/BalanceMobProps.java b/src/main/java/de/teamlapen/vampirism/config/BalanceMobProps.java index 72539e1b7c..7a1722bef8 100755 --- a/src/main/java/de/teamlapen/vampirism/config/BalanceMobProps.java +++ b/src/main/java/de/teamlapen/vampirism/config/BalanceMobProps.java @@ -13,6 +13,9 @@ public class BalanceMobProps { // @DefaultInt(value = 1, minValue = 0, name = "converted_mob_default_dmg") public final int CONVERTED_MOB_DEFAULT_DMG = 1; + public final int CONVERTED_MOB_DEFAULT_SPEED = 1; + public final int CONVERTED_MOB_DEFAULT_HEALTH = 1; + public final int CONVERTED_MOB_DEFAULT_KNOCKBACK_RESISTANCE = 0; // @DefaultInt(value = 60, comment = "Duration of the sanguinare effect for mobs in seconds", name = "sanguinare_avg_duration", minValue = 1) public final int SANGUINARE_AVG_DURATION = 30; diff --git a/src/main/java/de/teamlapen/vampirism/data/reloadlistener/ConvertiblesReloadListener.java b/src/main/java/de/teamlapen/vampirism/data/reloadlistener/ConvertiblesReloadListener.java index 9f70bb3724..2314d351ad 100644 --- a/src/main/java/de/teamlapen/vampirism/data/reloadlistener/ConvertiblesReloadListener.java +++ b/src/main/java/de/teamlapen/vampirism/data/reloadlistener/ConvertiblesReloadListener.java @@ -107,10 +107,10 @@ public record Attributes(FloatProvider damageProvider, FloatProvider knockBackRe public static final Codec CODEC = RecordCodecBuilder.create(inst -> { return inst.group( - FloatProvider.CODEC.optionalFieldOf("damage_multiplikator", ConstantFloat.of(1.3f)).forGetter(Attributes::damageProvider), - FloatProvider.CODEC.optionalFieldOf("knockback_resistance_multiplikator", ConstantFloat.of(1.3f)).forGetter(Attributes::knockBackResistanceProvider), - FloatProvider.CODEC.optionalFieldOf("max_health_multiplikator", ConstantFloat.of(1.5f)).forGetter(Attributes::maxHealthProvider), - FloatProvider.CODEC.optionalFieldOf("converted_speed_multiplikator", ConstantFloat.of(1.2f)).forGetter(Attributes::convertedSpeedProvider) + FloatProvider.CODEC.optionalFieldOf("damage_multiplikator", ConstantFloat.of(1f)).forGetter(Attributes::damageProvider), + FloatProvider.CODEC.optionalFieldOf("knockback_resistance_multiplikator", ConstantFloat.of(1f)).forGetter(Attributes::knockBackResistanceProvider), + FloatProvider.CODEC.optionalFieldOf("max_health_multiplikator", ConstantFloat.of(1f)).forGetter(Attributes::maxHealthProvider), + FloatProvider.CODEC.optionalFieldOf("converted_speed_multiplikator", ConstantFloat.of(1f)).forGetter(Attributes::convertedSpeedProvider) ).apply(inst, Attributes::new); }); diff --git a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedCowEntity.java b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedCowEntity.java index 957207bc40..4e0a24f689 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedCowEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedCowEntity.java @@ -20,8 +20,6 @@ import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; -import java.util.Optional; - public class ConvertedCowEntity extends ConvertedCreatureEntity { public ConvertedCowEntity(EntityType type, Level world) { super(type, world); @@ -61,13 +59,9 @@ public ConvertedCreatureEntity createFrom(@NotNull Cow entity) { public static class CowConverter extends DefaultConverter { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - ConvertiblesReloadListener.EntityEntry.Attributes.CODEC.optionalFieldOf("attribute_helper").forGetter(i -> Optional.ofNullable(i.helper)) + ConvertiblesReloadListener.EntityEntry.Attributes.CODEC.optionalFieldOf("attribute_helper", ConvertiblesReloadListener.EntityEntry.Attributes.DEFAULT).forGetter(i -> i.helper) ).apply(instance, CowConverter::new)); - protected CowConverter(Optional helper) { - super(helper); - } - public CowConverter(ConvertiblesReloadListener.EntityEntry.Attributes helper) { super(helper); } diff --git a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedSheepEntity.java b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedSheepEntity.java index 7ee6c003dc..fbf406a9b4 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedSheepEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedSheepEntity.java @@ -25,7 +25,6 @@ import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.Optional; /** * {@link IConvertedCreature} for sheep @@ -131,13 +130,9 @@ public ConvertedCreatureEntity createFrom(@NotNull Sheep entity) { public static class SheepConverter extends DefaultConverter { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - ConvertiblesReloadListener.EntityEntry.Attributes.CODEC.optionalFieldOf("attribute_helper").forGetter(i -> Optional.ofNullable(i.helper)) + ConvertiblesReloadListener.EntityEntry.Attributes.CODEC.optionalFieldOf("attribute_helper", ConvertiblesReloadListener.EntityEntry.Attributes.DEFAULT).forGetter(i -> i.helper) ).apply(instance, SheepConverter::new)); - protected SheepConverter(Optional helper) { - super(helper); - } - public SheepConverter(ConvertiblesReloadListener.EntityEntry.Attributes helper) { super(helper); } diff --git a/src/main/java/de/teamlapen/vampirism/entity/converted/VampirismEntityRegistry.java b/src/main/java/de/teamlapen/vampirism/entity/converted/VampirismEntityRegistry.java index af7b424e07..56e59b1d43 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/converted/VampirismEntityRegistry.java +++ b/src/main/java/de/teamlapen/vampirism/entity/converted/VampirismEntityRegistry.java @@ -205,19 +205,31 @@ public double getConvertedDMG(EntityType entity, Random @Override public double getConvertedKnockbackResistance(EntityType entity, RandomSource random) { AttributeSupplier map = DefaultAttributes.getSupplier(entity); - return map.getBaseValue(Attributes.KNOCKBACK_RESISTANCE) * this.attributes.knockBackResistanceProvider().sample(random); + if (map.hasAttribute(Attributes.KNOCKBACK_RESISTANCE)) { + return map.getBaseValue(Attributes.KNOCKBACK_RESISTANCE) * this.attributes.knockBackResistanceProvider().sample(random); + } else { + return BalanceMobProps.mobProps.CONVERTED_MOB_DEFAULT_KNOCKBACK_RESISTANCE; + } } @Override public double getConvertedMaxHealth(EntityType entity, RandomSource random) { AttributeSupplier map = DefaultAttributes.getSupplier(entity); - return map.getBaseValue(Attributes.MAX_HEALTH) * this.attributes.maxHealthProvider().sample(random); + if (map.hasAttribute(Attributes.MAX_HEALTH)) { + return map.getBaseValue(Attributes.MAX_HEALTH) * this.attributes.maxHealthProvider().sample(random); + } else { + return BalanceMobProps.mobProps.CONVERTED_MOB_DEFAULT_HEALTH; + } } @Override public double getConvertedSpeed(EntityType entity, RandomSource random) { AttributeSupplier map = DefaultAttributes.getSupplier(entity); - return Math.min(map.getBaseValue(Attributes.MOVEMENT_SPEED) * this.attributes.convertedSpeedProvider().sample(random), 2.9D); + if (map.hasAttribute(Attributes.MOVEMENT_SPEED)) { + return Math.min(map.getBaseValue(Attributes.MOVEMENT_SPEED) * this.attributes.convertedSpeedProvider().sample(random), 2.9D); + } else { + return BalanceMobProps.mobProps.CONVERTED_MOB_DEFAULT_SPEED; + } } } } \ No newline at end of file diff --git a/src/main/java/de/teamlapen/vampirism/entity/converted/converter/DefaultConverter.java b/src/main/java/de/teamlapen/vampirism/entity/converted/converter/DefaultConverter.java index 4967c5340e..122bf051a4 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/converted/converter/DefaultConverter.java +++ b/src/main/java/de/teamlapen/vampirism/entity/converted/converter/DefaultConverter.java @@ -9,20 +9,14 @@ import de.teamlapen.vampirism.entity.converted.DefaultConvertingHandler; import de.teamlapen.vampirism.entity.converted.VampirismEntityRegistry; -import java.util.Optional; - public class DefaultConverter implements Converter { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - ConvertiblesReloadListener.EntityEntry.Attributes.CODEC.optionalFieldOf("attribute_helper").forGetter(i -> Optional.ofNullable(i.helper)) + ConvertiblesReloadListener.EntityEntry.Attributes.CODEC.optionalFieldOf("attribute_helper", ConvertiblesReloadListener.EntityEntry.Attributes.DEFAULT).forGetter(i -> i.helper) ).apply(instance, DefaultConverter::new)); protected final ConvertiblesReloadListener.EntityEntry.Attributes helper; - protected DefaultConverter(Optional helper) { - this.helper = helper.orElseGet(() -> ConvertiblesReloadListener.EntityEntry.Attributes.DEFAULT); - } - public DefaultConverter(ConvertiblesReloadListener.EntityEntry.Attributes helper) { this.helper = helper; } diff --git a/src/main/java/de/teamlapen/vampirism/entity/converted/converter/SpecialConverter.java b/src/main/java/de/teamlapen/vampirism/entity/converted/converter/SpecialConverter.java index 251839fc3e..cb43b212a1 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/converted/converter/SpecialConverter.java +++ b/src/main/java/de/teamlapen/vampirism/entity/converted/converter/SpecialConverter.java @@ -13,22 +13,21 @@ import net.minecraft.world.entity.PathfinderMob; import net.minecraftforge.registries.ForgeRegistries; -import java.util.Optional; import java.util.function.Supplier; public class SpecialConverter> implements Converter { public static final Codec> CODEC = RecordCodecBuilder.create(instance -> instance.group( ForgeRegistries.ENTITY_TYPES.getCodec().fieldOf("converted_type").forGetter(i -> i.convertedType), - ConvertiblesReloadListener.EntityEntry.Attributes.CODEC.optionalFieldOf("attribute_helper").forGetter(i -> Optional.ofNullable(i.helper)) + ConvertiblesReloadListener.EntityEntry.Attributes.CODEC.optionalFieldOf("attribute_helper", ConvertiblesReloadListener.EntityEntry.Attributes.DEFAULT).forGetter(i -> i.helper) ).apply(instance, SpecialConverter::new)); private final EntityType convertedType; private final ConvertiblesReloadListener.EntityEntry.Attributes helper; - private SpecialConverter(EntityType convertedType, Optional helper) { + private SpecialConverter(EntityType convertedType, ConvertiblesReloadListener.EntityEntry.Attributes helper) { this.convertedType = (EntityType) convertedType; - this.helper = helper.orElseGet(() -> ConvertiblesReloadListener.EntityEntry.Attributes.DEFAULT); + this.helper = helper; } public SpecialConverter(Supplier> convertedType, ConvertiblesReloadListener.EntityEntry.Attributes helper) {