Skip to content

Commit

Permalink
modify converter default values and add attribute check
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed May 9, 2023
1 parent c30da36 commit b3190d5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public record Attributes(FloatProvider damageProvider, FloatProvider knockBackRe

public static final Codec<Attributes> 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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public class ConvertedCowEntity extends ConvertedCreatureEntity<Cow> {
public ConvertedCowEntity(EntityType<? extends ConvertedCreatureEntity> type, Level world) {
super(type, world);
Expand Down Expand Up @@ -61,13 +59,9 @@ public ConvertedCreatureEntity<Cow> createFrom(@NotNull Cow entity) {
public static class CowConverter extends DefaultConverter {

public static final Codec<CowConverter> 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<ConvertiblesReloadListener.EntityEntry.Attributes> helper) {
super(helper);
}

public CowConverter(ConvertiblesReloadListener.EntityEntry.Attributes helper) {
super(helper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;

/**
* {@link IConvertedCreature} for sheep
Expand Down Expand Up @@ -131,13 +130,9 @@ public ConvertedCreatureEntity<Sheep> createFrom(@NotNull Sheep entity) {
public static class SheepConverter extends DefaultConverter {

public static final Codec<SheepConverter> 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<ConvertiblesReloadListener.EntityEntry.Attributes> helper) {
super(helper);
}

public SheepConverter(ConvertiblesReloadListener.EntityEntry.Attributes helper) {
super(helper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,31 @@ public double getConvertedDMG(EntityType<? extends PathfinderMob> entity, Random
@Override
public double getConvertedKnockbackResistance(EntityType<? extends PathfinderMob> 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<? extends PathfinderMob> 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<? extends PathfinderMob> 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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultConverter> 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<ConvertiblesReloadListener.EntityEntry.Attributes> helper) {
this.helper = helper.orElseGet(() -> ConvertiblesReloadListener.EntityEntry.Attributes.DEFAULT);
}

public DefaultConverter(ConvertiblesReloadListener.EntityEntry.Attributes helper) {
this.helper = helper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends PathfinderMob, Z extends PathfinderMob & IConvertedCreature<T>> implements Converter {

public static final Codec<SpecialConverter<?, ?>> 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<Z> convertedType;
private final ConvertiblesReloadListener.EntityEntry.Attributes helper;

private SpecialConverter(EntityType<?> convertedType, Optional<ConvertiblesReloadListener.EntityEntry.Attributes> helper) {
private SpecialConverter(EntityType<?> convertedType, ConvertiblesReloadListener.EntityEntry.Attributes helper) {
this.convertedType = (EntityType<Z>) convertedType;
this.helper = helper.orElseGet(() -> ConvertiblesReloadListener.EntityEntry.Attributes.DEFAULT);
this.helper = helper;
}

public SpecialConverter(Supplier<EntityType<Z>> convertedType, ConvertiblesReloadListener.EntityEntry.Attributes helper) {
Expand Down

0 comments on commit b3190d5

Please sign in to comment.