Added an enchantment that alters the wearer's gravity

This commit is contained in:
Sollace 2021-02-17 17:05:20 +02:00
parent be59ed0553
commit 154c853bbd
3 changed files with 30 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.ability.magic.Spell;
import com.minelittlepony.unicopia.ability.magic.spell.SpellRegistry; import com.minelittlepony.unicopia.ability.magic.spell.SpellRegistry;
import com.minelittlepony.unicopia.entity.ai.WantItNeedItTargetGoal; import com.minelittlepony.unicopia.entity.ai.WantItNeedItTargetGoal;
import com.minelittlepony.unicopia.entity.ai.WantItTakeItGoal; import com.minelittlepony.unicopia.entity.ai.WantItTakeItGoal;
import com.minelittlepony.unicopia.entity.player.PlayerAttributes;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.GoalSelector; import net.minecraft.entity.ai.goal.GoalSelector;
@ -41,6 +42,7 @@ public class Creature extends Living<LivingEntity> {
public static void registerAttributes(DefaultAttributeContainer.Builder builder) { public static void registerAttributes(DefaultAttributeContainer.Builder builder) {
builder.add(EntityAttributes.GENERIC_ATTACK_DAMAGE); builder.add(EntityAttributes.GENERIC_ATTACK_DAMAGE);
builder.add(EntityAttributes.GENERIC_ATTACK_KNOCKBACK); builder.add(EntityAttributes.GENERIC_ATTACK_KNOCKBACK);
builder.add(PlayerAttributes.ENTITY_GRAVTY_MODIFIER);
} }
@Override @Override

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.entity; package com.minelittlepony.unicopia.entity;
import com.minelittlepony.unicopia.Owned; import com.minelittlepony.unicopia.Owned;
import com.minelittlepony.unicopia.entity.player.PlayerAttributes;
import com.minelittlepony.unicopia.util.Copieable; import com.minelittlepony.unicopia.util.Copieable;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -8,6 +9,7 @@ import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.FenceGateBlock; import net.minecraft.block.FenceGateBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
@ -89,6 +91,17 @@ public class EntityPhysics<T extends Owned<? extends Entity>> implements Physics
@Override @Override
public float getGravityModifier() { public float getGravityModifier() {
Entity master = pony.getMaster();
if (master instanceof LivingEntity) {
if (((LivingEntity)master).getAttributes() == null) {
// may be null due to order of execution in the constructor.
// Will have the default (1) here in any case, so it's safe to ignore the attribute at this point.
return gravity;
}
return gravity * (float)((LivingEntity)master).getAttributeValue(PlayerAttributes.ENTITY_GRAVTY_MODIFIER);
}
return gravity; return gravity;
} }

View file

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import com.minelittlepony.unicopia.entity.player.PlayerAttributes;
import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.Enchantment.Rarity; import net.minecraft.enchantment.Enchantment.Rarity;
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.EquipmentSlot;
@ -43,6 +45,14 @@ public interface UEnchantments {
*/ */
Enchantment COLLABORATOR = register("collaborator", new CollaboratorEnchantment()); Enchantment COLLABORATOR = register("collaborator", new CollaboratorEnchantment());
/**
* Alters gravity
*/
Enchantment REPULSION = register("repulsion", new AttributedEnchantment(Rarity.VERY_RARE, false, 3, EquipmentSlot.FEET))
.addModifier(PlayerAttributes.ENTITY_GRAVTY_MODIFIER, (user, level) -> {
return new EntityAttributeModifier(UUID.fromString("1734bbd6-1916-4124-b710-5450ea70fbdb"), "Anti Grav", (0.5F - (0.375 * (level - 1))) - 1, Operation.MULTIPLY_TOTAL);
});
/** /**
* I want it, I neeeed it! * I want it, I neeeed it!
* *
@ -62,6 +72,11 @@ public interface UEnchantments {
*/ */
Enchantment STRESS = register("stress", new StressfulEnchantment()); Enchantment STRESS = register("stress", new StressfulEnchantment());
/**
* This item just wants to be held.
*/
Enchantment CLINGY = register("clingy", new SimpleEnchantment(Rarity.VERY_RARE, true, 1, EquipmentSlot.values()));
static void bootstrap() { } static void bootstrap() { }
static <T extends SimpleEnchantment> T register(String name, T enchantment) { static <T extends SimpleEnchantment> T register(String name, T enchantment) {