-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dc5c3c
commit 6ffa73f
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/github/darksonic300/seidr/client/renderer/SoundBoomProjectileRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.darksonic300.seidr.client.renderer; | ||
|
||
import com.github.darksonic300.seidr.Seidr; | ||
import com.github.darksonic300.seidr.entity.projectile.SoundBoomProjectile; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.client.renderer.culling.Frustum; | ||
import net.minecraft.client.renderer.entity.EntityRenderer; | ||
import net.minecraft.client.renderer.entity.EntityRendererProvider; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class SoundBoomProjectileRenderer extends EntityRenderer<SoundBoomProjectile> { | ||
private static final RenderType RENDER_TYPE = RenderType.translucent(); | ||
|
||
protected SoundBoomProjectileRenderer(EntityRendererProvider.Context pContext) { | ||
super(pContext); | ||
} | ||
|
||
@Override | ||
public boolean shouldRender(SoundBoomProjectile pLivingEntity, Frustum pCamera, double pCamX, double pCamY, double pCamZ) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getTextureLocation(SoundBoomProjectile pEntity) { | ||
return ResourceLocation.fromNamespaceAndPath(Seidr.MODID, "textures/item/scroll_old.png"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/com/github/darksonic300/seidr/entity/projectile/SoundBoomProjectile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.github.darksonic300.seidr.entity.projectile; | ||
|
||
import com.github.darksonic300.seidr.entity.SeidrEntityTypes; | ||
import net.minecraft.core.particles.ParticleOptions; | ||
import net.minecraft.core.particles.ParticleTypes; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.projectile.AbstractHurtingProjectile; | ||
import net.minecraft.world.entity.projectile.ProjectileUtil; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.EntityHitResult; | ||
import net.minecraft.world.phys.HitResult; | ||
import net.minecraft.world.phys.Vec3; | ||
import net.neoforged.neoforge.event.EventHooks; | ||
|
||
public class SoundBoomProjectile extends AbstractHurtingProjectile { | ||
private int ticksInAir; | ||
|
||
public SoundBoomProjectile(EntityType<? extends AbstractHurtingProjectile> pEntityType, Level pLevel) { | ||
super(pEntityType, pLevel); | ||
this.setNoGravity(true); | ||
} | ||
|
||
public SoundBoomProjectile(Level level, LivingEntity shooter, double accelX, double accelY, double accelZ) { | ||
super(SeidrEntityTypes.SONIC_BOOM_PROJECTILE.get(), shooter, new Vec3(accelX, accelY, accelZ), level); | ||
this.setNoGravity(true); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
if (!this.onGround()) { | ||
++this.ticksInAir; | ||
} | ||
if (this.ticksInAir > 5) { | ||
if (!this.level().isClientSide()) { | ||
this.discard(); | ||
} | ||
} | ||
if (this.level().isClientSide() || (this.getOwner() == null || this.getOwner().isAlive()) && this.level().hasChunkAt(this.blockPosition())) { | ||
HitResult hitResult = ProjectileUtil.getHitResultOnMoveVector(this, this::canHitEntity); | ||
if (hitResult.getType() != HitResult.Type.MISS && !EventHooks.onProjectileImpact(this, hitResult)) { | ||
this.onHit(hitResult); | ||
} | ||
|
||
this.checkInsideBlocks(); | ||
Vec3 vec3 = this.getDeltaMovement(); | ||
double d0 = this.getX() + vec3.x(); | ||
double d1 = this.getY() + vec3.y(); | ||
double d2 = this.getZ() + vec3.z(); | ||
ProjectileUtil.rotateTowardsMovement(this, 0.2F); | ||
float f = this.getInertia(); | ||
|
||
this.setDeltaMovement(vec3.add(vec3.normalize().scale(this.accelerationPower)).scale((double)f)); | ||
ParticleOptions particleoptions = this.getTrailParticle(); | ||
if (particleoptions != null) { | ||
this.level().addParticle(particleoptions, d0, d1 + 0.5, d2, 0.0, 0.0, 0.0); | ||
} | ||
|
||
this.setPos(d0, d1, d2); | ||
} else { | ||
this.discard(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onHit(HitResult result) { | ||
super.onHit(result); | ||
if (!this.level().isClientSide()) { | ||
this.discard(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onHitEntity(EntityHitResult pResult) { | ||
super.onHitEntity(pResult); | ||
if (this.getOwner() instanceof LivingEntity owner) | ||
pResult.getEntity().hurt(damageSources().indirectMagic(owner, this), 20.0f); | ||
} | ||
|
||
@Override | ||
public void addAdditionalSaveData(CompoundTag tag) { | ||
super.addAdditionalSaveData(tag); | ||
tag.putInt("TicksInAir", this.ticksInAir); | ||
} | ||
|
||
@Override | ||
public void readAdditionalSaveData(CompoundTag tag) { | ||
super.readAdditionalSaveData(tag); | ||
if (tag.contains("TicksInAir")) { | ||
this.ticksInAir = tag.getInt("TicksInAir"); | ||
} | ||
} | ||
|
||
/** | ||
* Prevents this projectile from being on fire. | ||
*/ | ||
@Override | ||
protected boolean shouldBurn() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected ParticleOptions getTrailParticle() { | ||
return ParticleTypes.SONIC_BOOM; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters