Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cannonballs #19

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/main/java/ace/actually/pirates/entities/shot/ShotEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends ThrownItemEntity> entityType, World world, LivingEntity caster, Item toShow, float damageTo, String special) {
Expand All @@ -29,16 +30,23 @@ public ShotEntity(EntityType<? extends ThrownItemEntity> entityType, World world
setItem(new ItemStack(toShow));
damage=damageTo;
extra=special;
//setNoGravity(false);

}

public ShotEntity(World world)
{
super(Pirates.SHOT_ENTITY_TYPE, 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);
}
Expand All @@ -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();
}
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down