diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialStepAssist.java b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialStepAssist.java index 368c9239..74f39f40 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialStepAssist.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialStepAssist.java @@ -1,14 +1,19 @@ package org.cyclops.everlastingabilities.ability; +import com.google.common.collect.Maps; import com.mojang.serialization.Codec; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Rarity; +import net.minecraftforge.common.ForgeMod; import net.minecraftforge.common.crafting.conditions.ICondition; import org.cyclops.everlastingabilities.Reference; import org.cyclops.everlastingabilities.RegistryEntries; import org.cyclops.everlastingabilities.api.AbilityTypeAdapter; import org.cyclops.everlastingabilities.api.IAbilityType; +import java.util.Map; import java.util.Objects; /** @@ -17,14 +22,19 @@ */ public class AbilityTypeSpecialStepAssist extends AbilityTypeAdapter { - private static final String PLAYER_NBT_KEY = Reference.MOD_ID + ":" + "stepAssist"; - private final boolean forceDefaultStepHeight; + @Deprecated + private final boolean forceDefaultStepHeight; // TODO: rm in next MC version + private final Map attributeModifiers; public AbilityTypeSpecialStepAssist(ICondition condition, String name, Rarity rarity, int maxLevel, int baseXpPerLevel, boolean obtainableOnPlayerSpawn, boolean obtainableOnMobSpawn, boolean obtainableOnCraft, boolean obtainableOnLoot, boolean forceDefaultStepHeight) { super(condition, name, rarity, maxLevel, baseXpPerLevel, obtainableOnPlayerSpawn, obtainableOnMobSpawn, obtainableOnCraft, obtainableOnLoot); this.forceDefaultStepHeight = forceDefaultStepHeight; + this.attributeModifiers = Maps.newHashMap(); + for (int i = 1; i <= maxLevel; i++) { + this.attributeModifiers.put(i, new AttributeModifier(Reference.MOD_ID + ":stepHeightModifier" + i, i, AttributeModifier.Operation.ADDITION)); + } } @Override @@ -36,24 +46,16 @@ public boolean isForceDefaultStepHeight() { return forceDefaultStepHeight; } - @Override - public void onTick(Player player, int level) { - player.setMaxUpStep(player.isCrouching() ? 0.5F : level); - } - @Override public void onChangedLevel(Player player, int oldLevel, int newLevel) { - if (oldLevel > 0 && newLevel == 0) { - float stepHeight = 0.6F; - if(player.getPersistentData().contains(PLAYER_NBT_KEY)) { - if (!this.isForceDefaultStepHeight()) { - stepHeight = player.getPersistentData().getFloat(PLAYER_NBT_KEY); - } - player.getPersistentData().remove(PLAYER_NBT_KEY); + AttributeInstance attribute = player.getAttribute(ForgeMod.STEP_HEIGHT_ADDITION.get()); + if (attribute != null) { + if (oldLevel > 0) { + attribute.removeModifier(this.attributeModifiers.get(oldLevel)); + } + if (newLevel > 0) { + attribute.addPermanentModifier(this.attributeModifiers.get(newLevel)); } - player.setMaxUpStep(stepHeight); - } else if (oldLevel == 0 && newLevel > 0) { - player.getPersistentData().putFloat(PLAYER_NBT_KEY, player.maxUpStep()); } } }