优化迫击炮发射实现
This commit is contained in:
parent
6c50715d9a
commit
7e0a8aab38
2 changed files with 24 additions and 20 deletions
|
@ -1,6 +1,5 @@
|
||||||
package com.atsuishio.superbwarfare.entity.vehicle;
|
package com.atsuishio.superbwarfare.entity.vehicle;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.Mod;
|
|
||||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity;
|
import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
|
@ -95,30 +94,19 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fire(@Nullable LivingEntity shooter) {
|
private LivingEntity shooter = null;
|
||||||
if (!(this.stack.getItem() instanceof MortarShell shell)) return;
|
|
||||||
|
|
||||||
|
private void fire(@Nullable LivingEntity shooter) {
|
||||||
|
if (!(this.stack.getItem() instanceof MortarShell)) return;
|
||||||
|
|
||||||
|
this.shooter = shooter;
|
||||||
this.entityData.set(FIRE_TIME, 25);
|
this.entityData.set(FIRE_TIME, 25);
|
||||||
var stackToShoot = this.stack.copyWithCount(1);
|
|
||||||
this.stack = ItemStack.EMPTY;
|
|
||||||
|
|
||||||
if (!this.level().isClientSide()) {
|
if (!this.level().isClientSide()) {
|
||||||
this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_LOAD.get(), SoundSource.PLAYERS, 1f, 1f);
|
this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_LOAD.get(), SoundSource.PLAYERS, 1f, 1f);
|
||||||
this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_FIRE.get(), SoundSource.PLAYERS, 8f, 1f);
|
this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_FIRE.get(), SoundSource.PLAYERS, 8f, 1f);
|
||||||
this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_DISTANT.get(), SoundSource.PLAYERS, 32f, 1f);
|
this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_DISTANT.get(), SoundSource.PLAYERS, 32f, 1f);
|
||||||
}
|
}
|
||||||
Mod.queueServerWork(20, () -> {
|
|
||||||
Level level = this.level();
|
|
||||||
if (level instanceof ServerLevel server) {
|
|
||||||
MortarShellEntity entityToSpawn = shell.createShell(shooter, level, stackToShoot);
|
|
||||||
entityToSpawn.setPos(this.getX(), this.getEyeY(), this.getZ());
|
|
||||||
entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 11.4f, (float) 0.5);
|
|
||||||
level.addFreshEntity(entityToSpawn);
|
|
||||||
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
|
@Override
|
||||||
|
@ -205,8 +193,24 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container
|
||||||
@Override
|
@Override
|
||||||
public void baseTick() {
|
public void baseTick() {
|
||||||
super.baseTick();
|
super.baseTick();
|
||||||
if (this.entityData.get(FIRE_TIME) > 0) {
|
int fireTime = this.entityData.get(FIRE_TIME);
|
||||||
this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1);
|
if (fireTime > 0) {
|
||||||
|
this.entityData.set(FIRE_TIME, fireTime - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fireTime == 5 && this.stack.getItem() instanceof MortarShell) {
|
||||||
|
Level level = this.level();
|
||||||
|
if (level instanceof ServerLevel server) {
|
||||||
|
MortarShellEntity entityToSpawn = MortarShell.createShell(shooter, level, this.stack);
|
||||||
|
entityToSpawn.setPos(this.getX(), this.getEyeY(), this.getZ());
|
||||||
|
entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 11.4f, (float) 0.5);
|
||||||
|
level.addFreshEntity(entityToSpawn);
|
||||||
|
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);
|
||||||
|
|
||||||
|
this.stack = ItemStack.EMPTY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.move(MoverType.SELF, this.getDeltaMovement());
|
this.move(MoverType.SELF, this.getDeltaMovement());
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class MortarShell extends Item implements ProjectileItem {
|
||||||
super(new Properties());
|
super(new Properties());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MortarShellEntity createShell(@Nullable LivingEntity entity, Level level, ItemStack stack) {
|
public static MortarShellEntity createShell(@Nullable LivingEntity entity, Level level, ItemStack stack) {
|
||||||
MortarShellEntity shellEntity = new MortarShellEntity(entity, level);
|
MortarShellEntity shellEntity = new MortarShellEntity(entity, level);
|
||||||
shellEntity.setEffectsFromItem(stack);
|
shellEntity.setEffectsFromItem(stack);
|
||||||
return shellEntity;
|
return shellEntity;
|
||||||
|
|
Loading…
Add table
Reference in a new issue