/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.serialization.Codec * com.mojang.serialization.codecs.RecordCodecBuilder */ package net.minecraft.world.item.component; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.Optional; import net.minecraft.core.Holder; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.sounds.SoundEvent; import net.minecraft.util.ExtraCodecs; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.phys.EntityHitResult; public record PiercingWeapon(float minReach, float maxReach, float hitboxMargin, boolean dealsKnockback, boolean dismounts, Optional> sound, Optional> hitSound) { public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group((App)ExtraCodecs.floatRange(0.0f, 128.0f).optionalFieldOf("min_reach", (Object)Float.valueOf(0.0f)).forGetter(PiercingWeapon::minReach), (App)ExtraCodecs.floatRange(0.0f, 128.0f).optionalFieldOf("max_reach", (Object)Float.valueOf(3.0f)).forGetter(PiercingWeapon::maxReach), (App)ExtraCodecs.floatRange(0.0f, 1.0f).optionalFieldOf("hitbox_margin", (Object)Float.valueOf(0.3f)).forGetter(PiercingWeapon::hitboxMargin), (App)Codec.BOOL.optionalFieldOf("deals_knockback", (Object)true).forGetter(PiercingWeapon::dealsKnockback), (App)Codec.BOOL.optionalFieldOf("dismounts", (Object)false).forGetter(PiercingWeapon::dismounts), (App)SoundEvent.CODEC.optionalFieldOf("sound").forGetter(PiercingWeapon::sound), (App)SoundEvent.CODEC.optionalFieldOf("hit_sound").forGetter(PiercingWeapon::hitSound)).apply((Applicative)i, PiercingWeapon::new)); public static final StreamCodec STREAM_CODEC = StreamCodec.composite(ByteBufCodecs.FLOAT, PiercingWeapon::minReach, ByteBufCodecs.FLOAT, PiercingWeapon::maxReach, ByteBufCodecs.FLOAT, PiercingWeapon::hitboxMargin, ByteBufCodecs.BOOL, PiercingWeapon::dealsKnockback, ByteBufCodecs.BOOL, PiercingWeapon::dismounts, SoundEvent.STREAM_CODEC.apply(ByteBufCodecs::optional), PiercingWeapon::sound, SoundEvent.STREAM_CODEC.apply(ByteBufCodecs::optional), PiercingWeapon::hitSound, PiercingWeapon::new); public void makeSound(Entity causer) { this.sound.ifPresent(s -> causer.level().playSound(causer, causer.getX(), causer.getY(), causer.getZ(), (Holder)s, causer.getSoundSource(), 1.0f, 1.0f)); } public void makeHitSound(Entity causer) { this.hitSound.ifPresent(s -> causer.level().playSound(null, causer.getX(), causer.getY(), causer.getZ(), (Holder)s, causer.getSoundSource(), 1.0f, 1.0f)); } public static boolean canHitEntity(Entity jabber, Entity target) { if (!target.canBeHitByProjectile() || target.isInvulnerable() || !target.isAlive()) { return false; } if (target instanceof Player) { Player jabbingPlayer; Player targetPlayer = (Player)target; if (jabber instanceof Player && !(jabbingPlayer = (Player)jabber).canHarmPlayer(targetPlayer)) { return false; } } return !jabber.isPassengerOfSameVehicle(target); } public void attack(LivingEntity attacker, EquipmentSlot hand) { float damage = (float)attacker.getAttributeValue(Attributes.ATTACK_DAMAGE); boolean hitSomething = false; for (EntityHitResult hitResult : ProjectileUtil.getHitEntitiesAlong(attacker, this.minReach, this.maxReach, this.hitboxMargin, e -> PiercingWeapon.canHitEntity(attacker, e))) { hitSomething |= attacker.stabAttack(hand, hitResult.getEntity(), damage, true, this.dealsKnockback, this.dismounts); } attacker.onAttack(); attacker.lungeForwardMaybe(); if (hitSomething) { this.makeHitSound(attacker); } this.makeSound(attacker); attacker.swing(InteractionHand.MAIN_HAND, false); } }