I am trying to make a sword that shoots a warden blast (yes many cool), but the beam does not damage entities :(
ModDamageTypes.java
package net.magmabits.echoing_depths.util;
import net.magmabits.echoing_depths.EchoingDepths;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
public class ModDamageTypes {
/*
* Store the RegistryKey of our DamageType into a new constant called CUSTOM_DAMAGE_TYPE
* The Identifier in use here points to our JSON file we created earlier.
*/
public static final RegistryKey<DamageType> FALCHION_BLAST = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, new Identifier(EchoingDepths.MOD_ID, "falchion_blast"));
public static DamageSource of(World world, RegistryKey<DamageType> key) {
return new DamageSource(world.getRegistryManager().get(RegistryKeys.DAMAGE_TYPE).entryOf(key));
}
}
The part of my weapon code that should damage entities.
for (Entity entity : world.getOtherEntities(null, new Box(startX, startY, startZ, endX, endY, endZ))) {
if (entity instanceof LivingEntity && intersectsBeam(entity, beamStart, beamEnd)) {
((LivingEntity) entity).damage(ModDamageTypes.of(world, ModDamageTypes.FALCHION_BLAST), 8.0f);
}
}
All it does is crash :(