package net.mattias.oceancritteria.entity.custom.projectile;
import net.mattias.oceancritteria.OceanCritteria;
import net.mattias.oceancritteria.entity.ModEntities;
import net.mattias.oceancritteria.item.ModItems;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
public class IceArrow extends AbstractArrow {
// Constructor for registration - EntityType.Builder expects this exact signature
public IceArrow(EntityType<? extends AbstractArrow> entityType, Level level) {
super(entityType, level);
OceanCritteria.LOGGER.info("DEBUG: IceArrow created via registration constructor.");
}
// Constructor for when an entity shoots the arrow
public IceArrow(Level level, LivingEntity shooter) {
super(ModEntities.ICE_ARROW.get(), shooter, level);
OceanCritteria.LOGGER.info("DEBUG: IceArrow created by a shooter.");
}
@Override
protected ItemStack getPickupItem() {
return new ItemStack(ModItems.ICE_ARROW.get());
}
@Override
protected void onHitEntity(EntityHitResult pResult) {
super.onHitEntity(pResult);
Entity target = pResult.getEntity();
if (target instanceof LivingEntity livingTarget) {
// Apply Freeze Effect and Damage
int currentFreezeTicks = livingTarget.getTicksFrozen();
int newFreezeTicks = Math.min(currentFreezeTicks + 40, 140);
livingTarget.setTicksFrozen(newFreezeTicks);
livingTarget.addEffect(new MobEffectInstance(
MobEffects.MOVEMENT_SLOWDOWN,
60,
1,
false,
false
));
// Apply damage - adjust the amount as needed
float damageAmount = 2.0F; // Example damage
livingTarget.hurt(damageAmount, null);
// Apply the "frozen" visual effect (blue hearts)
livingTarget.addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 1, 0, false, false)); //Using blindness to get the blue hearts. It's a bit of a hack.
}
}
}
Key changes and explanations:
- Damage Application:
livingTarget.hurt(damageAmount, null); This line applies damage to the hit entity. damageAmount is a float that you can adjust to control how much damage the arrow deals. The null argument represents the source of the damage (in this case, the arrow itself).
- Blue Hearts (Powdered Snow Effect): The most reliable way to get the blue hearts effect is to apply the effect. It's a bit of a hack, as it doesn't actually cause blindness, but it visually changes the hearts to blue. I've added: