2020-04-27 18:30:44 +02:00
|
|
|
package de.ellpeck.naturesaura.entities;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|
|
|
import de.ellpeck.naturesaura.blocks.ModBlocks;
|
2021-12-05 23:32:31 +01:00
|
|
|
import net.minecraft.util.Mth;
|
|
|
|
import net.minecraft.world.entity.EntityType;
|
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
|
|
import net.minecraft.world.entity.projectile.ThrowableProjectile;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
|
|
import net.minecraft.world.phys.EntityHitResult;
|
|
|
|
import net.minecraft.world.phys.HitResult;
|
|
|
|
|
|
|
|
public class EntityLightProjectile extends ThrowableProjectile {
|
|
|
|
|
|
|
|
public EntityLightProjectile(EntityType<? extends ThrowableProjectile> type, Level levelIn) {
|
2021-12-04 15:40:09 +01:00
|
|
|
super(type, levelIn);
|
2020-04-27 18:30:44 +02:00
|
|
|
}
|
|
|
|
|
2021-12-05 23:32:31 +01:00
|
|
|
public EntityLightProjectile(EntityType<? extends ThrowableProjectile> type, LivingEntity livingEntityIn, Level levelIn) {
|
2021-12-04 15:40:09 +01:00
|
|
|
super(type, livingEntityIn, levelIn);
|
2020-04-27 18:30:44 +02:00
|
|
|
}
|
|
|
|
|
2021-12-05 23:32:31 +01:00
|
|
|
@Override
|
|
|
|
protected void defineSynchedData() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-27 18:30:44 +02:00
|
|
|
@Override
|
|
|
|
public void tick() {
|
|
|
|
super.tick();
|
2021-12-05 23:32:31 +01:00
|
|
|
if (this.level.isClientSide && this.tickCount > 1) {
|
2020-04-27 18:30:44 +02:00
|
|
|
for (float i = 0; i <= 1; i += 0.2F) {
|
|
|
|
NaturesAuraAPI.instance().spawnMagicParticle(
|
2021-12-05 23:32:31 +01:00
|
|
|
Mth.lerp(i, this.xOld, this.getX()),
|
|
|
|
Mth.lerp(i, this.yOld, this.getY()),
|
|
|
|
Mth.lerp(i, this.zOld, this.getZ()),
|
|
|
|
this.random.nextGaussian() * 0.01F, this.random.nextGaussian() * 0.01F, this.random.nextGaussian() * 0.01F,
|
|
|
|
0xffcb5c, this.random.nextFloat() * 0.5F + 1, 20, 0, false, true);
|
2020-04-27 18:30:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-05 23:32:31 +01:00
|
|
|
protected void onHit(HitResult result) {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!this.level.isClientSide) {
|
2021-12-05 23:32:31 +01:00
|
|
|
if (result instanceof BlockHitResult res) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var pos = res.getBlockPos().relative(res.getDirection());
|
|
|
|
var state = this.level.getBlockState(pos);
|
2020-04-27 18:30:44 +02:00
|
|
|
if (state.getMaterial().isReplaceable())
|
2021-12-05 23:32:31 +01:00
|
|
|
this.level.setBlockAndUpdate(pos, ModBlocks.LIGHT.defaultBlockState());
|
|
|
|
} else if (result instanceof EntityHitResult entity) {
|
2023-02-05 16:02:12 +01:00
|
|
|
entity.getEntity().setSecondsOnFire(5);
|
2020-04-27 18:30:44 +02:00
|
|
|
}
|
|
|
|
}
|
2021-12-05 23:32:31 +01:00
|
|
|
this.discard();
|
2020-04-27 18:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|