mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-03-03 16:51:28 +01:00
Earth Ponies can now steel themselves against damage by sneaking
This commit is contained in:
parent
7a3a441cb6
commit
27f143982e
4 changed files with 52 additions and 8 deletions
|
@ -17,6 +17,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
|
@ -139,13 +140,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
|||
|
||||
double radius = rad + heavyness * 0.3;
|
||||
|
||||
BlockPos.iterate(center.add(-radius, -radius, -radius), center.add(radius, radius, radius)).forEach(i -> {
|
||||
double dist = Math.sqrt(i.getSquaredDistance(player.getX(), player.getY(), player.getZ(), true));
|
||||
|
||||
if (dist <= radius) {
|
||||
spawnEffect(player.world, i, dist);
|
||||
}
|
||||
});
|
||||
spawnEffectAround(player, center, radius, rad);
|
||||
|
||||
ParticleUtils.spawnParticle(player.world, UParticles.GROUND_POUND, player.getX(), player.getY() - 1, player.getZ(), 0, 0, 0);
|
||||
|
||||
|
@ -153,7 +148,18 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
|||
});
|
||||
}
|
||||
|
||||
private void spawnEffect(World w, BlockPos pos, double dist) {
|
||||
public static void spawnEffectAround(Entity source, BlockPos center, double radius, double range) {
|
||||
|
||||
BlockPos.iterate(center.add(-radius, -radius, -radius), center.add(radius, radius, radius)).forEach(i -> {
|
||||
double dist = Math.sqrt(i.getSquaredDistance(source.getX(), source.getY(), source.getZ(), true));
|
||||
|
||||
if (dist <= radius) {
|
||||
spawnEffect(source.world, i, dist, range);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void spawnEffect(World w, BlockPos pos, double dist, double rad) {
|
||||
BlockState state = w.getBlockState(pos);
|
||||
BlockDestructionManager destr = ((BlockDestructionManager.Source)w).getDestructionManager();
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ public class PlayerAttributes implements Tickable {
|
|||
new EntityAttributeModifier(UUID.fromString("777a5505-521e-480b-b9d5-6ea54f259564"), "Earth Pony Strength", 0.6, Operation.MULTIPLY_TOTAL);
|
||||
private static final EntityAttributeModifier EARTH_PONY_MINING_SPEED =
|
||||
new EntityAttributeModifier(UUID.fromString("9fc9e269-152e-0b48-9bd5-564a546e59f2"), "Earth Pony Mining Speed", 0.4, Operation.MULTIPLY_TOTAL);
|
||||
private static final EntityAttributeModifier EARTH_PONY_KNOCKBACK_RESISTANCE =
|
||||
new EntityAttributeModifier(UUID.fromString("79e269a8-03e8-b9d5-5853-e25fdcf6706d"), "Earth Pony Knockback Resistance", 2, Operation.ADDITION);
|
||||
|
||||
private static final EntityAttributeModifier PEGASUS_SPEED =
|
||||
new EntityAttributeModifier(UUID.fromString("9e2699fc-3b8d-4f71-9d2d-fb92ee19b4f7"), "Pegasus Speed", 0.2, Operation.MULTIPLY_TOTAL);
|
||||
|
@ -50,6 +52,7 @@ public class PlayerAttributes implements Tickable {
|
|||
|
||||
toggleAttribute(entity, EntityAttributes.GENERIC_ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth());
|
||||
toggleAttribute(entity, EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, EARTH_PONY_STRENGTH, race.canUseEarth());
|
||||
toggleAttribute(entity, EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, EARTH_PONY_KNOCKBACK_RESISTANCE, race.canUseEarth() && entity.isSneaking());
|
||||
toggleAttribute(entity, EntityAttributes.GENERIC_MOVEMENT_SPEED, PEGASUS_SPEED, race.canFly());
|
||||
toggleAttribute(entity, EntityAttributes.GENERIC_ATTACK_SPEED, PEGASUS_SPEED, race.canFly());
|
||||
toggleAttribute(entity, EXTENDED_REACH_DISTANCE, PEGASUS_REACH, race.canFly());
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.minelittlepony.unicopia.Race;
|
|||
import com.minelittlepony.unicopia.UTags;
|
||||
import com.minelittlepony.unicopia.WorldTribeManager;
|
||||
import com.minelittlepony.unicopia.ability.AbilityDispatcher;
|
||||
import com.minelittlepony.unicopia.ability.EarthPonyStompAbility;
|
||||
import com.minelittlepony.unicopia.ability.magic.Affine;
|
||||
import com.minelittlepony.unicopia.ability.magic.Spell;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.SpellType;
|
||||
|
@ -43,6 +44,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.damage.EntityDamageSource;
|
||||
import net.minecraft.entity.data.DataTracker;
|
||||
import net.minecraft.entity.data.TrackedData;
|
||||
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
||||
|
@ -326,6 +328,21 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
|||
}
|
||||
}
|
||||
|
||||
public Optional<Float> modifyDamage(DamageSource cause, float amount) {
|
||||
|
||||
if (!cause.isUnblockable() && !cause.isMagic() && !cause.isFire() && !cause.isOutOfWorld()
|
||||
&& !(cause instanceof EntityDamageSource && ((EntityDamageSource)cause).isThorns())
|
||||
&& cause != DamageSource.FREEZE) {
|
||||
|
||||
if (getSpecies().canUseEarth() && entity.isSneaking()) {
|
||||
amount /= (cause.isProjectile() ? 3 : 2) * (entity.getHealth() < 5 ? 3 : 1);
|
||||
|
||||
return Optional.of(amount);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Float> onImpact(float distance, float damageMultiplier, DamageSource cause) {
|
||||
|
||||
float originalDistance = distance;
|
||||
|
@ -356,6 +373,18 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleFall(float distance, float damageMultiplier, DamageSource cause) {
|
||||
super.handleFall(distance, damageMultiplier, cause);
|
||||
|
||||
if (getSpecies().canUseEarth() && entity.isSneaking()) {
|
||||
double radius = distance / 10;
|
||||
if (radius > 0) {
|
||||
EarthPonyStompAbility.spawnEffectAround(entity, entity.getLandingPos(), radius, radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean subtractEnergyCost(double foodSubtract) {
|
||||
if (!entity.isCreative() && !entity.world.isClient) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.PonyContainer;
|
||||
|
@ -38,6 +39,11 @@ abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<P
|
|||
return new Pony((PlayerEntity)(Object)this);
|
||||
}
|
||||
|
||||
@ModifyVariable(method = "applyDamage(Lnet/minecraft/entity/damage/DamageSource;F)Z", at = @At("HEAD"), ordinal = 0)
|
||||
protected float modifyDamageAmount(float amount, DamageSource source) {
|
||||
return get().modifyDamage(source, amount).orElse(amount);
|
||||
}
|
||||
|
||||
@Inject(method = "handleFallDamage(FFLnet/minecraft/entity/damage/DamageSource;)Z", at = @At("HEAD"), cancellable = true)
|
||||
private void onHandleFallDamage(float distance, float damageMultiplier, DamageSource cause, CallbackInfoReturnable<Boolean> info) {
|
||||
get().onImpact(fallDistance, damageMultiplier, cause).ifPresent(newDistance -> {
|
||||
|
|
Loading…
Add table
Reference in a new issue