diff --git a/src/main/java/ace/actually/pirates/entities/shot/ShotEntity.java b/src/main/java/ace/actually/pirates/entities/shot/ShotEntity.java index f43edb5..da5b97e 100644 --- a/src/main/java/ace/actually/pirates/entities/shot/ShotEntity.java +++ b/src/main/java/ace/actually/pirates/entities/shot/ShotEntity.java @@ -21,6 +21,7 @@ public class ShotEntity extends ThrownItemEntity implements FlyingItemEntity { private LivingEntity in; private float damage=6; private String extra=""; + private int tickAge; public ShotEntity(EntityType entityType, World world, LivingEntity caster, Item toShow, float damageTo, String special) { @@ -29,9 +30,8 @@ public ShotEntity(EntityType entityType, World world setItem(new ItemStack(toShow)); damage=damageTo; extra=special; - //setNoGravity(false); - } + public ShotEntity(World world) { super(Pirates.SHOT_ENTITY_TYPE, world); @@ -39,6 +39,14 @@ public ShotEntity(World world) @Override public void tick () { + if (this.tickAge > 500) { + if (!this.getWorld().isClient()) { + explode(); + } + } else { + this.tickAge++; + } + if (!getWorld().isClient() && getVelocity().length() > 0.85) { ((ServerWorld)getWorld()).spawnParticles(ParticleTypes.CLOUD, getX(), getY(), getZ(), 1, 0, 0, 0, 0); } @@ -49,8 +57,7 @@ public void tick () { protected void onCollision(HitResult hitResult) { super.onCollision(hitResult); if (!this.getWorld().isClient) { - this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), 2.2f, extra.contains("fire"), World.ExplosionSourceType.TNT); - this.discard(); + explode(); } } @@ -60,11 +67,15 @@ protected void onEntityHit(EntityHitResult entityHitResult) { Entity entity = entityHitResult.getEntity(); entity.damage(this.getDamageSources().explosion(null), damage); if (!this.getWorld().isClient) { - this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), 2.2f, extra.contains("fire"), World.ExplosionSourceType.TNT); - this.discard(); + explode(); } } + private void explode() { + this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), 2.2f, extra.contains("fire"), World.ExplosionSourceType.TNT); + this.discard(); + } + @Override protected Item getDefaultItem() { return Pirates.CANNONBALL_ENT; diff --git a/src/main/java/ace/actually/pirates/util/CannonDispenserBehavior.java b/src/main/java/ace/actually/pirates/util/CannonDispenserBehavior.java index 2662d8a..bfbe4c8 100644 --- a/src/main/java/ace/actually/pirates/util/CannonDispenserBehavior.java +++ b/src/main/java/ace/actually/pirates/util/CannonDispenserBehavior.java @@ -11,6 +11,9 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.Position; import net.minecraft.world.World; +import org.valkyrienskies.core.api.ships.Ship; +import org.valkyrienskies.mod.common.VSGameUtilsKt; +import org.valkyrienskies.mod.common.util.VectorConversionsMCKt; /** * 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) { ProjectileEntity projectileEntity = this.createProjectile(world, position, stack); projectileEntity.setVelocity(direction.getOffsetX(), (float)direction.getOffsetY() + 0.15f, direction.getOffsetZ(), this.getForce() + 0.6f, this.getVariation() / 2); world.spawnEntity(projectileEntity); + + Ship ship = VSGameUtilsKt.getShipManagingPos(world, pointer.getPos()); + if (ship != null) { + projectileEntity.addVelocity(VectorConversionsMCKt.toMinecraft(ship.getVelocity()).multiply(1/60.0)); + } + if (!world.isClient) { int xmod = 0; int ymod = 0; int zmod = 0; - if (direction == Direction.NORTH) { - zmod = -1; - } else if (direction == Direction.EAST) { - xmod = 1; - } else if (direction == Direction.SOUTH) { - zmod = 1; - } else if (direction == Direction.WEST) { - xmod = -1; - } else if (direction == Direction.UP) { - ymod = 1; - } else if (direction == Direction.DOWN) { - ymod = -1; + + switch (direction) { + case NORTH -> zmod = -1; + case EAST -> xmod = 1; + case SOUTH -> zmod = 1; + case WEST -> xmod = -1; + case UP -> ymod = 1; + case DOWN -> ymod = -1; } for(int i = 0; i < 40; ++i) { 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);