Skip to content

Commit

Permalink
Merge pull request #601 from imreallybadatnames/1.20.1-aria-for-painters
Browse files Browse the repository at this point in the history
Refactor Puff Circlet fall negation logic.
  • Loading branch information
DaFuqs authored Nov 24, 2024
2 parents f43f722 + e711952 commit f2a80ae
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions src/main/java/de/dafuqs/spectrum/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import de.dafuqs.spectrum.status_effects.*;
import dev.emi.trinkets.api.*;
import net.fabricmc.fabric.api.tag.convention.v1.*;
import net.minecraft.block.*;
import net.minecraft.enchantment.*;
import net.minecraft.entity.*;
import net.minecraft.entity.attribute.*;
Expand Down Expand Up @@ -334,7 +333,7 @@ else if (source.isIn(SpectrumDamageTypeTags.INCREASED_ARMOR_DAMAGE)) {
return protection;
}

@ModifyVariable(method = "applyArmorToDamage", at = @At("STORE"), ordinal = 0)
@ModifyVariable(method = "applyArmorToDamage", at = @At("STORE"), ordinal = 0, argsOnly = true)
private float spectrum$applyArmorToDamage(float amount, DamageSource source) {
float defense = getArmor();
float toughness = getToughness();
Expand Down Expand Up @@ -386,34 +385,34 @@ private float getToughness() {
return (float) this.getAttributeValue(EntityAttributes.GENERIC_ARMOR_TOUGHNESS);
}

@Inject(at = @At("HEAD"), method = "fall(DZLnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;)V")
private void spectrum$fall(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition, CallbackInfo ci) {
if (onGround) {
LivingEntity thisEntity = (LivingEntity) (Object) this;
if (!thisEntity.isInvulnerableTo(thisEntity.getDamageSources().fall()) && thisEntity.fallDistance > thisEntity.getSafeFallDistance()) {
Optional<TrinketComponent> component = TrinketsApi.getTrinketComponent(thisEntity);
if (component.isPresent()) {
if (!component.get().getEquipped(SpectrumItems.PUFF_CIRCLET).isEmpty()) {
var charges = AzureDikeProvider.getAzureDikeCharges(thisEntity);
if (charges > 0) {
AzureDikeProvider.absorbDamage(thisEntity, PuffCircletItem.FALL_DAMAGE_NEGATING_COST);

thisEntity.fallDistance = 0;
thisEntity.setVelocity(thisEntity.getVelocity().x, 0.5, thisEntity.getVelocity().z);
World world = thisEntity.getWorld();
if (world.isClient) { // it is split here so the particles spawn immediately, without network lag
ParticleHelper.playParticleWithPatternAndVelocityClient(thisEntity.getWorld(), thisEntity.getPos(), SpectrumParticleTypes.WHITE_CRAFTING, VectorPattern.EIGHT, 0.4);
ParticleHelper.playParticleWithPatternAndVelocityClient(thisEntity.getWorld(), thisEntity.getPos(), SpectrumParticleTypes.BLUE_CRAFTING, VectorPattern.EIGHT_OFFSET, 0.5);
} else if (thisEntity instanceof ServerPlayerEntity serverPlayerEntity) {
SpectrumS2CPacketSender.playParticleWithPatternAndVelocity(serverPlayerEntity, (ServerWorld) thisEntity.getWorld(), thisEntity.getPos(), SpectrumParticleTypes.WHITE_CRAFTING, VectorPattern.EIGHT, 0.4);
SpectrumS2CPacketSender.playParticleWithPatternAndVelocity(serverPlayerEntity, (ServerWorld) thisEntity.getWorld(), thisEntity.getPos(), SpectrumParticleTypes.BLUE_CRAFTING, VectorPattern.EIGHT_OFFSET, 0.5);
}
thisEntity.getWorld().playSound(null, thisEntity.getBlockPos(), SpectrumSoundEvents.PUFF_CIRCLET_PFFT, SoundCategory.PLAYERS, 1.0F, 1.0F);
}
}
}
}
@Inject(method = "handleFallDamage", at = @At("HEAD"), cancellable = true)
private void spectrum$puffCircletDamageNegation(float fallDistance, float damageMultiplier, DamageSource damageSource, CallbackInfoReturnable<Boolean> cir) {
LivingEntity thisEntity = (LivingEntity) (Object) this;
// check if damage reduction is applicable to this entity
if (thisEntity.isInvulnerableTo(thisEntity.getDamageSources().fall()) || AzureDikeProvider.getAzureDikeCharges(thisEntity) <= 0) return;

// check if this entity is protected by puff circlet
Optional<TrinketComponent> component = TrinketsApi.getTrinketComponent(thisEntity);
if (component.isEmpty() || component.get().getEquipped(SpectrumItems.PUFF_CIRCLET).isEmpty()) return;

// do damage reduction
AzureDikeProvider.absorbDamage(thisEntity, PuffCircletItem.FALL_DAMAGE_NEGATING_COST);

// yoink
Vec3d velocity = thisEntity.getVelocity();
thisEntity.setVelocity(velocity.getX(), 0.5, velocity.getZ());
World world = thisEntity.getWorld();
if (world.isClient) { // it is split here so the particles spawn immediately, without network lag
ParticleHelper.playParticleWithPatternAndVelocityClient(thisEntity.getWorld(), thisEntity.getPos(), SpectrumParticleTypes.WHITE_CRAFTING, VectorPattern.EIGHT, 0.4);
ParticleHelper.playParticleWithPatternAndVelocityClient(thisEntity.getWorld(), thisEntity.getPos(), SpectrumParticleTypes.BLUE_CRAFTING, VectorPattern.EIGHT_OFFSET, 0.5);
} else if (thisEntity instanceof ServerPlayerEntity serverPlayerEntity) {
SpectrumS2CPacketSender.playParticleWithPatternAndVelocity(serverPlayerEntity, (ServerWorld) thisEntity.getWorld(), thisEntity.getPos(), SpectrumParticleTypes.WHITE_CRAFTING, VectorPattern.EIGHT, 0.4);
SpectrumS2CPacketSender.playParticleWithPatternAndVelocity(serverPlayerEntity, (ServerWorld) thisEntity.getWorld(), thisEntity.getPos(), SpectrumParticleTypes.BLUE_CRAFTING, VectorPattern.EIGHT_OFFSET, 0.5);
}
thisEntity.getWorld().playSound(null, thisEntity.getBlockPos(), SpectrumSoundEvents.PUFF_CIRCLET_PFFT, SoundCategory.PLAYERS, 1.0F, 1.0F);

// at last, cancel the function
cir.setReturnValue(false);
}

@ModifyVariable(at = @At("HEAD"), method = "damage(Lnet/minecraft/entity/damage/DamageSource;F)Z", argsOnly = true)
Expand Down

0 comments on commit f2a80ae

Please sign in to comment.