-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation 20241228 - Full Cannon Turret
Implemented the entirety of Cannon Turret, along with its projectile, sounds, animations, and effects. [CHANGELOG] 🟢 Added the Cannonball Model class. 🟢 Added the Cannonball Renderer class. 🟢 Added the Cannonball Entity class. 🟢 Added entity registry methods in the Registry Utility class. 🟢 Added Cannonball resources (model and texture). 🟢 Added bullet impacting metal sound files. 🟢 Added bullet impacting wood sound files. 🟢 Added metal repair sound files. 🟡 Updated the projectile of Cannon Turret entity. 🟡 Updated sound ID of "Turret Metal Repair" from "turret.repair.iron" to "turret.repair.metal". 🟡 Fixed typo for the Arrowhead death message. 🟡 Updated item tooltip regarding Cannon Turret item's range from 20 to 16, matching the real range of the turret entity. 🟡 Updated sounds.json to properly reflect changes done to the sound lists. 🟡 Renamed the bullet impacting dirt sounds to start from 1 instead of 3. 🟡 Updated cannonball texture to have transparent background instead of black. 🔴 Removed the TODO in the Cannon Turret Model class.
- Loading branch information
Showing
24 changed files
with
330 additions
and
44 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
35 changes: 35 additions & 0 deletions
35
src/client/java/com/virus5600/defensive_measures/model/projectiles/CannonballModel.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,35 @@ | ||
package com.virus5600.defensive_measures.model.projectiles; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.util.Identifier; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import software.bernie.geckolib.model.GeoModel; | ||
import software.bernie.geckolib.renderer.GeoRenderer; | ||
|
||
import com.virus5600.defensive_measures.DefensiveMeasures; | ||
import com.virus5600.defensive_measures.entity.projectiles.CannonballEntity; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class CannonballModel extends GeoModel<CannonballEntity> { | ||
///////////////////////// | ||
/// INTERFACE METHODS /// | ||
///////////////////////// | ||
|
||
@Override | ||
public Identifier getModelResource(CannonballEntity cannonballEntity, @Nullable GeoRenderer<CannonballEntity> geoRenderer) { | ||
return Identifier.of(DefensiveMeasures.MOD_ID, "geo/projectiles/cannonball.geo.json"); | ||
} | ||
|
||
@Override | ||
public Identifier getTextureResource(CannonballEntity cannonballEntity, @Nullable GeoRenderer<CannonballEntity> geoRenderer) { | ||
return Identifier.of(DefensiveMeasures.MOD_ID, "textures/entity/cannon_turret/cannonball.png"); | ||
} | ||
|
||
@Override | ||
public Identifier getAnimationResource(CannonballEntity animatable) { | ||
return null; | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...client/java/com/virus5600/defensive_measures/renderer/projectiles/CannonballRenderer.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,22 @@ | ||
package com.virus5600.defensive_measures.renderer.projectiles; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
|
||
import net.minecraft.client.render.entity.EntityRendererFactory.Context; | ||
import software.bernie.geckolib.renderer.GeoEntityRenderer; | ||
|
||
import com.virus5600.defensive_measures.entity.projectiles.CannonballEntity; | ||
import com.virus5600.defensive_measures.model.projectiles.CannonballModel; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class CannonballRenderer extends GeoEntityRenderer<CannonballEntity> { | ||
public CannonballRenderer(Context ctx) { | ||
super(ctx, new CannonballModel()); | ||
} | ||
|
||
@Override | ||
protected float getDeathMaxRotation(CannonballEntity animatable, float partialTick) { | ||
return 0.0f; | ||
} | ||
} |
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
188 changes: 188 additions & 0 deletions
188
src/main/java/com/virus5600/defensive_measures/entity/projectiles/CannonballEntity.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,188 @@ | ||
package com.virus5600.defensive_measures.entity.projectiles; | ||
|
||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.entity.projectile.ExplosiveProjectileEntity; | ||
import net.minecraft.particle.ParticleEffect; | ||
import net.minecraft.particle.ParticleTypes; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.sound.SoundEvent; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.hit.EntityHitResult; | ||
import net.minecraft.util.hit.HitResult; | ||
import net.minecraft.util.math.Box; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.explosion.ExplosionBehavior; | ||
|
||
import software.bernie.geckolib.animatable.GeoEntity; | ||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; | ||
import software.bernie.geckolib.animation.AnimatableManager.ControllerRegistrar; | ||
import software.bernie.geckolib.util.GeckoLibUtil; | ||
|
||
import com.virus5600.defensive_measures.entity.ModEntities; | ||
|
||
public class CannonballEntity extends ExplosiveProjectileEntity implements GeoEntity { | ||
private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); | ||
private LivingEntity shooter; | ||
|
||
//////////////////// | ||
/// CONSTRUCTORS /// | ||
//////////////////// | ||
public CannonballEntity(EntityType<? extends ExplosiveProjectileEntity> entityType, World world) { | ||
super(entityType, world); | ||
this.setFireTicks(0); | ||
this.setOnFire(false); | ||
this.setNoGravity(false); | ||
} | ||
|
||
public CannonballEntity(World world, LivingEntity owner) { | ||
this(ModEntities.CANNONBALL, world); | ||
this.setOwner(owner); | ||
} | ||
|
||
public CannonballEntity(LivingEntity owner, double directionX, double directionY, double directionZ, World world) { | ||
this(world, owner); | ||
this.setVelocity(directionX, directionY, directionZ); | ||
} | ||
|
||
/////////////// | ||
/// METHODS /// | ||
/////////////// | ||
// PROTECTED | ||
@Override | ||
protected void onBlockHit(BlockHitResult blockHitResult) { | ||
super.onBlockHit(blockHitResult); | ||
|
||
if (!this.getWorld().isClient) { | ||
this.doDamage(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onEntityHit(EntityHitResult entityHitResult) { | ||
if (!this.getWorld().isClient) { | ||
this.doDamage(); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean isBurning() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected ParticleEffect getParticleType() { | ||
return ParticleTypes.CLOUD; | ||
} | ||
|
||
@Override | ||
protected void onCollision(HitResult hitResult) { | ||
super.onCollision(hitResult); | ||
if (!this.getWorld().isClient) { | ||
this.doDamage(); | ||
} | ||
} | ||
|
||
protected RegistryEntry.Reference<SoundEvent> getHitSound() { | ||
return SoundEvents.ENTITY_GENERIC_EXPLODE; | ||
} | ||
|
||
// PUBLIC | ||
private double radius = 0; | ||
public void doDamage() { | ||
// Create damage source | ||
DamageSource dmgSrc = this.getDamageSources().explosion( | ||
this, | ||
this.getOwner() == null ? this : this.getOwner() | ||
); | ||
|
||
// Create explosion | ||
this.getWorld() | ||
.createExplosion( | ||
this, | ||
dmgSrc, | ||
new ExplosionBehavior(), | ||
this.getX(), | ||
this.getBodyY(0.0625), | ||
this.getZ(), | ||
1.25F, | ||
false, | ||
World.ExplosionSourceType.NONE | ||
); | ||
|
||
// Damage entities within a 4 block radius | ||
double maxEffectiveDmgRad = 2; | ||
double maxDmgRad = 4; | ||
double dmgReduction = 3.75; | ||
double baseDmg = 10; | ||
|
||
for (radius = 0; radius < maxDmgRad; radius += 0.25) { | ||
if (radius < maxEffectiveDmgRad) radius += 0.75; | ||
|
||
double x1 = MathHelper.floor(this.getX() - radius - 1.0D); | ||
double x2 = MathHelper.floor(this.getX() + radius + 1.0D); | ||
double y1 = MathHelper.floor(this.getY() - radius - 1.0D); | ||
double y2 = MathHelper.floor(this.getY() + radius + 1.0D); | ||
double z1 = MathHelper.floor(this.getZ() - radius - 1.0D); | ||
double z3 = MathHelper.floor(this.getZ() + radius + 1.0D); | ||
|
||
this.getWorld() | ||
.getOtherEntities( | ||
this, | ||
new Box(x1, y1, z1, x2, y2, z3) | ||
) | ||
.forEach(entity -> { | ||
float dmg = (float) baseDmg; | ||
|
||
if (radius > maxEffectiveDmgRad) { | ||
dmg -= (float) (dmgReduction * (radius - maxEffectiveDmgRad)); | ||
} | ||
|
||
if (entity instanceof LivingEntity) { | ||
entity.damage( | ||
(ServerWorld) this.getWorld(), | ||
dmgSrc, | ||
dmg | ||
); | ||
} | ||
}); | ||
} | ||
|
||
this.discard(); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
super.tick(); | ||
|
||
double acceleration = 0.08; | ||
if (!this.hasNoGravity()) { | ||
this.setVelocity( | ||
this.getVelocity() | ||
.add( | ||
0, | ||
-acceleration / 4.0, | ||
0 | ||
) | ||
); | ||
} | ||
} | ||
|
||
///////////////////////////////// | ||
/// INTERFACE IMPLEMENTATIONS /// | ||
///////////////////////////////// | ||
|
||
// GeoEntity // | ||
@Override | ||
public void registerControllers(final ControllerRegistrar controllers) { | ||
} | ||
|
||
@Override | ||
public AnimatableInstanceCache getAnimatableInstanceCache() { | ||
return this.geoCache; | ||
} | ||
} |
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
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
Oops, something went wrong.