添加发射功能

This commit is contained in:
Atsuishio 2025-07-13 23:41:37 +08:00 committed by Light_Quanta
parent 4f3c41def4
commit 0d175a9dbc
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 61 additions and 2 deletions

View file

@ -203,9 +203,10 @@ public class MediumRocketEntity extends FastThrowableProjectile implements GeoEn
@Override
public void onHitEntity(@NotNull EntityHitResult entityHitResult) {
if (tickCount < 2) return;
if (this.level() instanceof ServerLevel) {
Entity entity = entityHitResult.getEntity();
if (this.getOwner() != null && entity == this.getOwner().getVehicle())
if (this.getOwner() != null && entity == this.getOwner().getVehicle() && tickCount < 2)
return;
entity.hurt(ModDamageTypes.causeCannonFireDamage(this.level().registryAccess(), this, this.getOwner()), this.damage);
@ -267,7 +268,7 @@ public class MediumRocketEntity extends FastThrowableProjectile implements GeoEn
active = true;
}
if (tickCount >= sparedTime && active) {
if (tickCount >= sparedTime && active && type == Type.CM) {
releaseClusterMunitions((LivingEntity) getOwner());
this.discard();
}

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.vehicle;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.OBBEntity;
import com.atsuishio.superbwarfare.entity.projectile.MediumRocketEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModSerializers;
@ -185,9 +186,11 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
return InteractionResult.SUCCESS;
}
} else {
// 撬棍发射
for (int i = 0; i < 12; i++) {
if (items.get(i).getItem() instanceof MediumRocketItem) {
items.set(i, ItemStack.EMPTY);
shoot(player, i);
setChanged();
player.swing(InteractionHand.MAIN_HAND);
return InteractionResult.SUCCESS;
@ -208,6 +211,61 @@ public class Type63Entity extends ContainerMobileVehicleEntity implements GeoEnt
}
}
public void shoot(Player player, int i) {
if (level() instanceof ServerLevel server) {
ItemStack stack = items.get(i);
float damage;
float radius;
float explosionDamage;
float fireProbability;
int fireTime;
MediumRocketEntity.Type type;
int sparedAmount;
if (stack.is(ModItems.MEDIUM_ROCKET_AP.get())) {
damage = 500;
radius = 6;
explosionDamage = 100;
fireProbability = 0;
fireTime = 0;
type = MediumRocketEntity.Type.AP;
sparedAmount = 0;
} else if (stack.is(ModItems.MEDIUM_ROCKET_HE.get())) {
damage = 200;
radius = 12;
explosionDamage = 200;
fireProbability = 0.2f;
fireTime = 40;
type = MediumRocketEntity.Type.HE;
sparedAmount = 0;
} else {
damage = 300;
radius = 12;
explosionDamage = 300;
fireProbability = 0;
fireTime = 0;
type = MediumRocketEntity.Type.CM;
sparedAmount = 20;
}
OBB obb = this.barrel[i];
Vec3 shootPos = new Vec3(obb.center());
MediumRocketEntity entityToSpawn = new MediumRocketEntity(player, server, damage, radius, explosionDamage, fireProbability, fireTime, type, sparedAmount);
entityToSpawn.setPos(shootPos.x, shootPos.y, shootPos.z);
entityToSpawn.shoot(getShootVector(1).x, getShootVector(1).y, getShootVector(1).z, 10, (float) 0.25);
server.addFreshEntity(entityToSpawn);
server.playSound(null, shootPos.x, shootPos.y, shootPos.z, ModSounds.MEDIUM_ROCKET_FIRE.get(), SoundSource.PLAYERS, 4f, random.nextFloat() * 0.1f + 0.95f);
// server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, (this.getX() + 3 * this.getLookAngle().x), (this.getY() + 0.1 + 3 * this.getLookAngle().y), (this.getZ() + 3 * this.getLookAngle().z), 8, 0.4, 0.4, 0.4,
// 0.007);
// server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), 50, 2, 0.02, 2, 0.0005);
}
}
@Override
public void baseTick() {
turretYRotO = this.getTurretYRot();