Skip to content

Commit c71a4fa

Browse files
committed
Update 20250319 - Refactorization and Update
Updated the target version to the latest one while also refactoring some base classes. [CHANGELOG] 🟢 Added some more documentations. 🟢 Added some default interface implementations to some base classes. 🟢 Added two new abstract methods for the `TurretProjectileEntity` super class, allowing more control over armor affected attributes. 🟢 Added a new Enum, which purpose is to define an entity's armor type based on its armor point. 🟡 Updated the dependencies' versions in the gradle properties. 🟡 Renamed `BulletEntity` to `MGBulletEntity`. 🟡 Moved the code that modifies the piercing, damage, and velocity of a projectile based on armor from the base class `KineticProjectileEntity` to its parent base class `TurretProjectileEntity`. 🟡 Changed parameter names of `MGBulletEntity(World, LivingEntity)` constructor to match their uses. 🟡 Updated the `MGBulletEntity` class's max pierce level from 0 to 5. 🔴 Removed unused imports.
1 parent d743228 commit c71a4fa

File tree

8 files changed

+244
-138
lines changed

8 files changed

+244
-138
lines changed

gradle.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ org.gradle.parallel=true
44

55
# Fabric Properties
66
# check these on https://fabricmc.net/develop
7-
minecraft_version=1.21.3
8-
yarn_mappings=1.21.3+build.2
9-
loader_version=0.16.9
7+
minecraft_version=1.21.4
8+
yarn_mappings=1.21.4+build.8
9+
loader_version=0.16.10
1010

1111
# Mod Properties
1212
mod_version = 1.0.1-beta-1.21
1313
maven_group = com.virus5600
1414
archives_base_name = defensive-measures
1515

1616
# Dependencies
17-
fabric_version=0.110.0+1.21.3
18-
geckolib_version=4.7.1
17+
fabric_version=0.119.0+1.21.4
18+
geckolib_version=4.8.4

src/main/java/com/virus5600/defensive_measures/entity/ModEntities.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public class ModEntities {
6262
.trackingTickInterval(10)
6363
);
6464

65-
public static final EntityType<BulletEntity> MG_BULLET = RegistryUtil.registerEntity(
65+
public static final EntityType<MGBulletEntity> MG_BULLET = RegistryUtil.registerEntity(
6666
"mg_bullet",
6767
Builder
68-
.<BulletEntity>create(BulletEntity::new, SpawnGroup.MISC)
68+
.<MGBulletEntity>create(MGBulletEntity::new, SpawnGroup.MISC)
6969
.dropsNothing()
7070
.dimensions(0.125f, 0.125f)
7171
.maxTrackingRange(4)

src/main/java/com/virus5600/defensive_measures/entity/projectiles/BallistaArrowEntity.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515

1616
import java.util.Map;
1717

18+
/**
19+
* BallistaArrowEntity
20+
*
21+
* <p>Represents a ballista arrow projectile entity that pierces through multiple entities.</p>
22+
* <p>
23+
* The ballista arrow is a {@link KineticProjectileEntity kinetic projectile}
24+
* that is fired from a {@link com.virus5600.defensive_measures.entity.turrets.BallistaTurretEntity ballista turret}.
25+
* </p>
26+
* <p>
27+
* This projectile can pierce through multiple entities, dealing 4 hearts of damage to each
28+
* entity it hits. The arrow can pierce through a maximum of 5 entities before it is destroyed.
29+
* And everytime it pierces through an entity, it will reduce its pierce level its speed
30+
* depending on the armor of the entity it hit.
31+
* </p>
32+
* To see how the reduction mechanics work, check {@link KineticProjectileEntity}.
33+
*/
1834
public class BallistaArrowEntity extends KineticProjectileEntity {
1935
private static final Map<String, RawAnimation> ANIMATIONS;
2036

src/main/java/com/virus5600/defensive_measures/entity/projectiles/CannonballEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ public void tick() {
203203
super.tick();
204204
}
205205

206-
/////////////////////////////////
207-
/// INTERFACE IMPLEMENTATIONS ///
208-
/////////////////////////////////
206+
// ///////////////////////// //
207+
// INTERFACE IMPLEMENTATIONS //
208+
// ///////////////////////// //
209209

210210
// GeoEntity //
211211
@Override

src/main/java/com/virus5600/defensive_measures/entity/projectiles/ExplosiveProjectileEntity.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828
import java.util.ArrayList;
2929
import java.util.List;
3030

31+
/**
32+
* {@code ExplosiveProjectileEntity} is an abstract class that extends {@link TurretProjectileEntity}.
33+
* This class is used to represent a projectile entity that explodes on impact, dealing damage to
34+
* entities within a certain radius. This class is used to represent explosive projectiles, such as
35+
* cannonballs, missiles, and other similar projectiles.
36+
* <br><br>
37+
* By default, the explosive projectile entity has the following behavior:
38+
* <ul>
39+
* <li>Armor points affect the piercing of the projectile.</li>
40+
* <li>Armor points do not affect the speed of the projectile.</li>
41+
* <li>Armor points do not affect the base damage dealt by the projectile.</li>
42+
* <li>Base damage is set to 5.</li>
43+
* </ul>
44+
*/
3145
public abstract class ExplosiveProjectileEntity extends TurretProjectileEntity {
3246
protected ParticleEffect particleTrail;
3347
public double accelerationPower = 0.1;
@@ -442,4 +456,24 @@ public void onSpawnPacket(EntitySpawnS2CPacket packet) {
442456
Vec3d vec3d = new Vec3d(packet.getVelocityX(), packet.getVelocityY(), packet.getVelocityZ());
443457
this.setVelocity(vec3d);
444458
}
459+
460+
// //////////////////////// //
461+
// INTERFACE IMPLEMENTATION //
462+
// //////////////////////// //
463+
464+
// PUBLIC
465+
@Override
466+
public boolean armorAffectsPiercing() {
467+
return true;
468+
}
469+
470+
@Override
471+
public boolean armorAffectsVelocity() {
472+
return false;
473+
}
474+
475+
@Override
476+
public boolean armorAffectsDamage() {
477+
return false;
478+
}
445479
}
Lines changed: 26 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
package com.virus5600.defensive_measures.entity.projectiles;
22

3-
import net.minecraft.entity.Entity;
4-
import net.minecraft.entity.LivingEntity;
53
import net.minecraft.entity.data.DataTracker.Builder;
64
import net.minecraft.entity.EntityType;
7-
import net.minecraft.util.hit.EntityHitResult;
85
import net.minecraft.world.World;
96

7+
/**
8+
* {@code KineticProjectileEntity} is an abstract class that extends {@link TurretProjectileEntity}.
9+
* This class is used to represent a projectile entity that uses kinetic energy to deal damage
10+
* to entities, such as arrows, bullets, and other similar projectiles.
11+
* <br><br>
12+
* By default, the kinetic projectile entity has the following behavior:
13+
* <ul>
14+
* <li>Armor points affect the piercing of the projectile.</li>
15+
* <li>Armor points affect the speed of the projectile.</li>
16+
* <li>Armor points affect the base damage dealt by the projectile.</li>
17+
* <li>Base damage is set to 4.</li>
18+
* </ul>
19+
*/
1020
public abstract class KineticProjectileEntity extends TurretProjectileEntity {
1121

1222
// ///////////// //
@@ -28,118 +38,23 @@ protected void initDataTracker(Builder builder) {
2838
super.initDataTracker(builder);
2939
}
3040

31-
/**
32-
* {@inheritDoc}
33-
* <hr>
34-
* <h2>{@link KineticProjectileEntity}</h2>
35-
* <br><br>
36-
* The method in {@code KineticProjectileEntity} reduces the speed of the arrow
37-
* along with the pierce level based on the amount of armor points the entity has.
38-
* <br><br>
39-
* In this implementation, the projectile will have the following behavior
40-
* (assuming the projectile is affected by armor points):
41-
* <table>
42-
* <tr>
43-
* <th>Armor Points</th>
44-
* <th>Pierce Level Reduction</th>
45-
* <th>Velocity Reduction</th>
46-
* <th>Base Damage Reduction</th>
47-
* </tr>
48-
* <tr>
49-
* <td>Heavy Armor</td>
50-
* <td>2</td>
51-
* <td>50%</td>
52-
* <td>50%</td>
53-
* </tr>
54-
* <tr>
55-
* <td>Light Armor</td>
56-
* <td>1</td>
57-
* <td>25%</td>
58-
* <td>20%</td>
59-
* </tr>
60-
* <tr>
61-
* <td>No Armor</td>
62-
* <td>N/A</td>
63-
* <td>12.5%</td>
64-
* <td>5%</td>
65-
* </tr>
66-
* </table>
67-
*
68-
* @param entityHitResult {@inheritDoc EntityHitResult}
69-
*/
70-
@Override
71-
protected void onEntityHit(EntityHitResult entityHitResult) {
72-
super.onEntityHit(entityHitResult);
73-
74-
if (this.armorAffectsPiercing()) {
75-
// Reduces the speed of the arrow when it hits an entity
76-
Entity entity = entityHitResult.getEntity();
77-
// For reference, max armor points is 30
78-
int armor = entity instanceof LivingEntity livingEntity ? livingEntity.getArmor() : 0;
79-
double dmgReduction = 0.05;
80-
boolean hasHeavyArmor = armor > 15,
81-
hasLightArmor = armor <= 15 && armor > 0;
82-
83-
if (entity instanceof LivingEntity livingEntity) {
84-
double targetH = livingEntity.getHeight(),
85-
arrowH = this.getHeight(),
86-
variance = arrowH * 0.125; // 12.5% of the arrow's height
87-
88-
double arrowMin = arrowH - variance,
89-
arrowMax = arrowH + variance,
90-
reducedVelocity = 0.125;
91-
92-
// Reduce velocity and pierce level based on the side of the entity hit
93-
if (this.getPierceLevel() > 0) {
94-
// If the arrow is smaller than the target or has heavy armor, reduce the pierce level by 2, velocity by 50%, and base damage by 50%
95-
if (targetH > arrowMax || hasHeavyArmor) {
96-
this.setPierceLevel((byte) (this.getPierceLevel() - 2));
97-
reducedVelocity = 0.5;
98-
dmgReduction = 0.5;
99-
}
100-
// If the arrow is almost the same size as the target or has a light armor, reduce the pierce level by 1, velocity by 25%, and base damage by 20%
101-
else if ((targetH < arrowMax && arrowMin < targetH) || hasLightArmor) {
102-
this.setPierceLevel((byte) (this.getPierceLevel() - 1));
103-
reducedVelocity = 0.25;
104-
dmgReduction = 0.2;
105-
}
106-
// Otherwise, just reduce the velocity by 12.5% and base damage by 5% without reducing the pierce level
107-
}
41+
// ///////////////////////// //
42+
// INTERFACE IMPLEMENTATIONS //
43+
// ///////////////////////// //
10844

109-
// Apply reduced velocity
110-
this.addVelocity(
111-
this.getVelocity()
112-
.multiply(reducedVelocity)
113-
.negate()
114-
);
115-
116-
// Apply reduced damage
117-
this.setDamage(this.getDamage() * (1 - dmgReduction));
118-
}
119-
120-
this.addVelocity(
121-
this.getVelocity()
122-
.negate()
123-
.multiply(0.1)
124-
);
125-
}
45+
// PUBLIC
46+
@Override
47+
public boolean armorAffectsPiercing() {
48+
return true;
12649
}
12750

128-
// /////////////////////////////// //
129-
// GETTERS, SETTERS, AND QUESTIONS //
130-
// /////////////////////////////// //
51+
@Override
52+
public boolean armorAffectsVelocity() {
53+
return true;
54+
}
13155

132-
// PUBLIC
133-
/**
134-
* An overridable method that determines whether an armor point affects the
135-
* piercing of the projectile.
136-
* <br><br>
137-
* By default, this method returns {@code true}.
138-
*
139-
* @return {@code true} if the armor point affects the piercing of the projectile,
140-
* {@code false} otherwise.
141-
*/
142-
public boolean armorAffectsPiercing() {
56+
@Override
57+
public boolean armorAffectsDamage() {
14358
return true;
14459
}
14560
}

src/main/java/com/virus5600/defensive_measures/entity/projectiles/BulletEntity.java renamed to src/main/java/com/virus5600/defensive_measures/entity/projectiles/MGBulletEntity.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import net.minecraft.entity.EntityType;
44
import net.minecraft.entity.LivingEntity;
5-
import net.minecraft.entity.data.DataTracker;
65
import net.minecraft.entity.data.DataTracker.Builder;
76
import net.minecraft.item.ItemStack;
87
import net.minecraft.world.World;
@@ -13,33 +12,33 @@
1312

1413
import com.virus5600.defensive_measures.entity.ModEntities;
1514

16-
public class BulletEntity extends TurretProjectileEntity {
15+
public class MGBulletEntity extends TurretProjectileEntity {
1716
private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);
1817

1918
////////////////////
2019
/// CONSTRUCTORS ///
2120
////////////////////
22-
public BulletEntity(
21+
public MGBulletEntity(
2322
EntityType<? extends TurretProjectileEntity> entityType,
2423
World world
2524
) {
2625
super(entityType, world);
2726
}
2827

29-
public BulletEntity(World world, LivingEntity owner) {
28+
public MGBulletEntity(World world, LivingEntity owner) {
3029
this(ModEntities.MG_BULLET, world);
3130
this.setOwner(owner);
3231
}
3332

34-
public BulletEntity(
33+
public MGBulletEntity(
3534
LivingEntity owner,
36-
double directionX,
37-
double directionY,
38-
double directionZ,
35+
double velocityX,
36+
double velocityY,
37+
double velocityZ,
3938
World world
4039
) {
4140
this(world, owner);
42-
this.setVelocity(directionX, directionY, directionZ);
41+
this.setVelocity(velocityX, velocityY, velocityZ);
4342
}
4443

4544
///////////////
@@ -57,7 +56,7 @@ protected final void setPierceLevel(byte pierceLevel) {
5756
}
5857

5958
public byte getMaxPierceLevel() {
60-
return 0;
59+
return 5;
6160
}
6261

6362
@Override

0 commit comments

Comments
 (0)