Skip to content

Commit 515a632

Browse files
authored
Merge pull request #19 from jamesgreen26/1.20
Improve cannonballs
2 parents d586062 + 6d795d5 commit 515a632

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

src/main/java/ace/actually/pirates/entities/shot/ShotEntity.java

+17-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ShotEntity extends ThrownItemEntity implements FlyingItemEntity {
2121
private LivingEntity in;
2222
private float damage=6;
2323
private String extra="";
24+
private int tickAge;
2425

2526

2627
public ShotEntity(EntityType<? extends ThrownItemEntity> entityType, World world, LivingEntity caster, Item toShow, float damageTo, String special) {
@@ -29,16 +30,23 @@ public ShotEntity(EntityType<? extends ThrownItemEntity> entityType, World world
2930
setItem(new ItemStack(toShow));
3031
damage=damageTo;
3132
extra=special;
32-
//setNoGravity(false);
33-
3433
}
34+
3535
public ShotEntity(World world)
3636
{
3737
super(Pirates.SHOT_ENTITY_TYPE, world);
3838
}
3939

4040
@Override
4141
public void tick () {
42+
if (this.tickAge > 500) {
43+
if (!this.getWorld().isClient()) {
44+
explode();
45+
}
46+
} else {
47+
this.tickAge++;
48+
}
49+
4250
if (!getWorld().isClient() && getVelocity().length() > 0.85) {
4351
((ServerWorld)getWorld()).spawnParticles(ParticleTypes.CLOUD, getX(), getY(), getZ(), 1, 0, 0, 0, 0);
4452
}
@@ -49,8 +57,7 @@ public void tick () {
4957
protected void onCollision(HitResult hitResult) {
5058
super.onCollision(hitResult);
5159
if (!this.getWorld().isClient) {
52-
this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), 2.2f, extra.contains("fire"), World.ExplosionSourceType.TNT);
53-
this.discard();
60+
explode();
5461
}
5562
}
5663

@@ -60,11 +67,15 @@ protected void onEntityHit(EntityHitResult entityHitResult) {
6067
Entity entity = entityHitResult.getEntity();
6168
entity.damage(this.getDamageSources().explosion(null), damage);
6269
if (!this.getWorld().isClient) {
63-
this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), 2.2f, extra.contains("fire"), World.ExplosionSourceType.TNT);
64-
this.discard();
70+
explode();
6571
}
6672
}
6773

74+
private void explode() {
75+
this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), 2.2f, extra.contains("fire"), World.ExplosionSourceType.TNT);
76+
this.discard();
77+
}
78+
6879
@Override
6980
protected Item getDefaultItem() {
7081
return Pirates.CANNONBALL_ENT;

src/main/java/ace/actually/pirates/util/CannonDispenserBehavior.java

+17-12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import net.minecraft.util.math.Direction;
1212
import net.minecraft.util.math.Position;
1313
import net.minecraft.world.World;
14+
import org.valkyrienskies.core.api.ships.Ship;
15+
import org.valkyrienskies.mod.common.VSGameUtilsKt;
16+
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;
1417

1518
/**
1619
* A dispenser behavior that spawns a projectile with velocity in front of the dispenser.
@@ -25,22 +28,24 @@ public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
2528
ProjectileEntity projectileEntity = this.createProjectile(world, position, stack);
2629
projectileEntity.setVelocity(direction.getOffsetX(), (float)direction.getOffsetY() + 0.15f, direction.getOffsetZ(), this.getForce() + 0.6f, this.getVariation() / 2);
2730
world.spawnEntity(projectileEntity);
31+
32+
Ship ship = VSGameUtilsKt.getShipManagingPos(world, pointer.getPos());
33+
if (ship != null) {
34+
projectileEntity.addVelocity(VectorConversionsMCKt.toMinecraft(ship.getVelocity()).multiply(1/60.0));
35+
}
36+
2837
if (!world.isClient) {
2938
int xmod = 0;
3039
int ymod = 0;
3140
int zmod = 0;
32-
if (direction == Direction.NORTH) {
33-
zmod = -1;
34-
} else if (direction == Direction.EAST) {
35-
xmod = 1;
36-
} else if (direction == Direction.SOUTH) {
37-
zmod = 1;
38-
} else if (direction == Direction.WEST) {
39-
xmod = -1;
40-
} else if (direction == Direction.UP) {
41-
ymod = 1;
42-
} else if (direction == Direction.DOWN) {
43-
ymod = -1;
41+
42+
switch (direction) {
43+
case NORTH -> zmod = -1;
44+
case EAST -> xmod = 1;
45+
case SOUTH -> zmod = 1;
46+
case WEST -> xmod = -1;
47+
case UP -> ymod = 1;
48+
case DOWN -> ymod = -1;
4449
}
4550
for(int i = 0; i < 40; ++i) {
4651
world.spawnParticles(ParticleTypes.CLOUD, position.getX() + xmod + (2 * world.random.nextDouble()) - 1, position.getY() + ymod + (2 * world.random.nextDouble()) - 0.8, position.getZ() + zmod + (2 * world.random.nextDouble()) - 1, 1, 0.0, 0.0, 0.0, 0.005);

0 commit comments

Comments
 (0)