适配更多移动音效
This commit is contained in:
parent
95be8a3bbe
commit
30be20c0b0
20 changed files with 330 additions and 134 deletions
|
@ -0,0 +1,115 @@
|
|||
package com.atsuishio.superbwarfare.client;
|
||||
|
||||
import com.atsuishio.superbwarfare.entity.LoudlyEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.sounds.AbstractTickableSoundInstance;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
public abstract class LoudlyEntitySoundInstance extends AbstractTickableSoundInstance {
|
||||
private final Minecraft client;
|
||||
private final Entity entity;
|
||||
private double lastDistance;
|
||||
private int fade = 0;
|
||||
private boolean die = false;
|
||||
|
||||
public LoudlyEntitySoundInstance(SoundEvent sound, Minecraft client, Entity entity) {
|
||||
super(sound, SoundSource.AMBIENT, entity.getCommandSenderWorld().getRandom());
|
||||
this.client = client;
|
||||
this.entity = entity;
|
||||
this.looping = true;
|
||||
this.delay = 0;
|
||||
}
|
||||
|
||||
protected abstract boolean canPlay(Entity entity);
|
||||
|
||||
protected abstract float getPitch(Entity entity);
|
||||
|
||||
protected abstract float getVolume(Entity entity);
|
||||
@Override
|
||||
public void tick() {
|
||||
var player = this.client.player;
|
||||
if (entity.isRemoved() || player == null) {
|
||||
this.stop();
|
||||
return;
|
||||
} else if (!this.canPlay(entity)) {
|
||||
this.die = true;
|
||||
}
|
||||
|
||||
if (this.die) {
|
||||
if (this.fade > 0) this.fade--;
|
||||
else if (this.fade == 0) {
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
} else if (this.fade < 3) {
|
||||
this.fade++;
|
||||
}
|
||||
|
||||
this.volume = this.getVolume(this.entity) * fade;
|
||||
|
||||
this.x = this.entity.getX();
|
||||
this.y = this.entity.getY();
|
||||
this.z = this.entity.getZ();
|
||||
|
||||
this.pitch = this.getPitch(this.entity);
|
||||
|
||||
if (player.getVehicle() != this.entity) {
|
||||
double distance = this.entity.position().subtract(player.position()).length();
|
||||
this.pitch += (float) (0.16 * java.lang.Math.atan(lastDistance - distance));
|
||||
|
||||
this.lastDistance = distance;
|
||||
} else {
|
||||
this.lastDistance = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntitySound extends LoudlyEntitySoundInstance {
|
||||
public EntitySound(Entity entity) {
|
||||
super(entity instanceof LoudlyEntity loudlyEntity ? loudlyEntity.getSound() : null, Minecraft.getInstance(), entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canPlay(Entity entity) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getPitch(Entity entity) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getVolume(Entity entity) {
|
||||
if (entity instanceof LoudlyEntity loudlyEntity) {
|
||||
return loudlyEntity.getVolume();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntitySoundClose extends LoudlyEntitySoundInstance {
|
||||
public EntitySoundClose(Entity entity) {
|
||||
super(entity instanceof LoudlyEntity loudlyEntity ? loudlyEntity.getCloseSound() : null, Minecraft.getInstance(), entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canPlay(Entity entity) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getPitch(Entity entity) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getVolume(Entity entity) {
|
||||
if (entity instanceof LoudlyEntity loudlyEntity) {
|
||||
return loudlyEntity.getVolume() * 1.5f;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package com.atsuishio.superbwarfare.client;
|
||||
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.Tom6Entity;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.resources.sounds.AbstractTickableSoundInstance;
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class PlayerSoundInstance extends AbstractTickableSoundInstance {
|
||||
private final LocalPlayer player;
|
||||
|
||||
public PlayerSoundInstance(LocalPlayer pPlayer) {
|
||||
super(SoundEvents.ELYTRA_FLYING, SoundSource.PLAYERS, SoundInstance.createUnseededRandom());
|
||||
this.player = pPlayer;
|
||||
this.looping = true;
|
||||
this.delay = 0;
|
||||
this.volume = 0.1F;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
if (!this.player.isRemoved() && (this.player.getVehicle() instanceof Tom6Entity tom6Entity)) {
|
||||
this.x = player.getX();
|
||||
this.y = player.getY();
|
||||
this.z = player.getZ();
|
||||
float $$0 = (float)tom6Entity.getDeltaMovement().lengthSqr();
|
||||
if ((double)$$0 >= 1.0E-7) {
|
||||
this.volume = Mth.clamp($$0 / 4.0F, 0.0F, 1.0F);
|
||||
} else {
|
||||
this.volume = 0.0F;
|
||||
}
|
||||
} else {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,17 @@
|
|||
package com.atsuishio.superbwarfare.client;
|
||||
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.sounds.AbstractTickableSoundInstance;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public abstract class VehicleSoundInstance extends AbstractTickableSoundInstance {
|
||||
private final Minecraft client;
|
||||
|
@ -28,6 +33,7 @@ public abstract class VehicleSoundInstance extends AbstractTickableSoundInstance
|
|||
protected abstract float getPitch(MobileVehicleEntity mobileVehicle);
|
||||
|
||||
protected abstract float getVolume(MobileVehicleEntity mobileVehicle);
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
var player = this.client.player;
|
||||
|
@ -64,6 +70,14 @@ public abstract class VehicleSoundInstance extends AbstractTickableSoundInstance
|
|||
} else {
|
||||
this.lastDistance = 0;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModItems.MONITOR.get()) && NBTTool.getTag(stack).getBoolean("Using")) {
|
||||
DroneEntity drone = EntityFindUtil.findDrone(player.level(), NBTTool.getTag(stack).getString("LinkedDrone"));
|
||||
if (this.mobileVehicle == drone) {
|
||||
pitch = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class EngineSound extends VehicleSoundInstance {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.atsuishio.superbwarfare.entity;
|
||||
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
|
||||
public interface LoudlyEntity {
|
||||
|
||||
SoundEvent getCloseSound ();
|
||||
SoundEvent getSound ();
|
||||
|
||||
float getVolume();
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.entity.projectile;
|
||||
|
||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||
import com.atsuishio.superbwarfare.entity.LoudlyEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.*;
|
||||
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
|
||||
|
@ -15,6 +16,7 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
@ -40,7 +42,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CannonShellEntity extends FastThrowableProjectile implements GeoEntity {
|
||||
public class CannonShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity {
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
private float damage = 0;
|
||||
|
@ -332,4 +334,19 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
|
|||
}
|
||||
super.onRemovedFromLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getCloseSound() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getSound() {
|
||||
return ModSounds.SHELL_FLY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume() {
|
||||
return 0.07f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.entity.projectile;
|
||||
|
||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||
import com.atsuishio.superbwarfare.entity.LoudlyEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
|
@ -11,6 +12,7 @@ import com.atsuishio.superbwarfare.tools.ParticleTool;
|
|||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
@ -32,7 +34,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class HeliRocketEntity extends FastThrowableProjectile implements GeoEntity {
|
||||
public class HeliRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity {
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
private float damage = 140f;
|
||||
|
@ -162,4 +164,19 @@ public class HeliRocketEntity extends FastThrowableProjectile implements GeoEnti
|
|||
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
||||
return this.cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getCloseSound() {
|
||||
return ModSounds.ROCKET_ENGINE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getSound() {
|
||||
return ModSounds.ROCKET_FLY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume() {
|
||||
return 0.1f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.entity.projectile;
|
||||
|
||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||
import com.atsuishio.superbwarfare.entity.LoudlyEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
|
@ -16,6 +17,7 @@ import net.minecraft.network.syncher.EntityDataSerializers;
|
|||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -48,7 +50,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class JavelinMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity {
|
||||
public class JavelinMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity {
|
||||
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<Boolean> TOP = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
|
@ -371,4 +373,19 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
|
|||
public boolean shouldSyncMotion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getCloseSound() {
|
||||
return ModSounds.ROCKET_ENGINE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getSound() {
|
||||
return ModSounds.ROCKET_FLY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume() {
|
||||
return 0.4f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.atsuishio.superbwarfare.entity.projectile;
|
||||
|
||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||
import com.atsuishio.superbwarfare.entity.LoudlyEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.tools.ChunkLoadTool;
|
||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||
|
@ -16,6 +18,7 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.AreaEffectCloud;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
@ -44,7 +47,7 @@ import java.util.HashSet;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class MortarShellEntity extends FastThrowableProjectile implements GeoEntity {
|
||||
public class MortarShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity {
|
||||
|
||||
private float damage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get();
|
||||
private int life = 600;
|
||||
|
@ -280,4 +283,19 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
|
|||
}
|
||||
level.addFreshEntity(cloud);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getCloseSound() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getSound() {
|
||||
return ModSounds.SHELL_FLY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume() {
|
||||
return 0.06f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.entity.projectile;
|
||||
|
||||
import com.atsuishio.superbwarfare.entity.LoudlyEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
|
@ -11,6 +12,7 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
@ -30,7 +32,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
|||
import software.bernie.geckolib.animation.*;
|
||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntity {
|
||||
public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity {
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
|
@ -193,4 +195,19 @@ public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntit
|
|||
public boolean shouldSyncMotion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getCloseSound() {
|
||||
return ModSounds.ROCKET_ENGINE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getSound() {
|
||||
return ModSounds.ROCKET_FLY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume() {
|
||||
return 0.2f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.entity.projectile;
|
||||
|
||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||
import com.atsuishio.superbwarfare.entity.LoudlyEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
|
@ -17,6 +18,7 @@ import net.minecraft.network.syncher.EntityDataSerializers;
|
|||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
|
@ -43,7 +45,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity {
|
||||
public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity {
|
||||
|
||||
public static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(SwarmDroneEntity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<Float> TARGET_X = SynchedEntityData.defineId(SwarmDroneEntity.class, EntityDataSerializers.FLOAT);
|
||||
|
@ -287,4 +289,19 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti
|
|||
public boolean shouldSyncMotion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getCloseSound() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getSound() {
|
||||
return ModSounds.DRONE_SOUND.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume() {
|
||||
return 0.07f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.entity.projectile;
|
||||
|
||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||
import com.atsuishio.superbwarfare.entity.LoudlyEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
|
@ -17,6 +18,7 @@ import net.minecraft.network.syncher.EntityDataSerializers;
|
|||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.damagesource.DamageTypes;
|
||||
|
@ -42,7 +44,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class WgMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity {
|
||||
public class WgMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity {
|
||||
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(WgMissileEntity.class, EntityDataSerializers.FLOAT);
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
|
@ -234,4 +236,19 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
|
|||
public boolean shouldSyncMotion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getCloseSound() {
|
||||
return ModSounds.ROCKET_ENGINE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getSound() {
|
||||
return ModSounds.ROCKET_FLY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVolume() {
|
||||
return 0.4f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,9 +187,9 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
ItemStack stack = controller.getMainHandItem();
|
||||
var tag = NBTTool.getTag(stack);
|
||||
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using")) {
|
||||
if (controller.level().isClientSide) {
|
||||
controller.playSound(ModSounds.DRONE_SOUND.get(), 114, 1);
|
||||
}
|
||||
// if (controller.level().isClientSide) {
|
||||
// controller.playSound(ModSounds.DRONE_SOUND.get(), 114, 1);
|
||||
// }
|
||||
} else {
|
||||
upInputDown = false;
|
||||
downInputDown = false;
|
||||
|
@ -395,7 +395,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
holdTickZ = 0;
|
||||
}
|
||||
|
||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.94, 0.55, 0.94));
|
||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.97, 0.94, 0.97));
|
||||
} else {
|
||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.8, 1, 0.8));
|
||||
this.setZRot(this.roll * 0.7f);
|
||||
|
@ -413,28 +413,36 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
|
||||
if (up) {
|
||||
holdTickY++;
|
||||
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.06f * Math.min(holdTickY, 5), 0.9f));
|
||||
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.02f * Math.min(holdTickY, 5), 0.4f));
|
||||
} else if (down) {
|
||||
holdTickY++;
|
||||
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.06f * Math.min(holdTickY, 5), -0.9f));
|
||||
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.02f * Math.min(holdTickY, 5), this.onGround() ? 0 : 0.01f));
|
||||
} else {
|
||||
holdTickY = 0;
|
||||
}
|
||||
|
||||
this.entityData.set(POWER, this.entityData.get(POWER) * 0.7f);
|
||||
if (!(up || down)) {
|
||||
if (this.getDeltaMovement().y() < 0) {
|
||||
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.01f, 0.4f));
|
||||
} else {
|
||||
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.01f, 0f));
|
||||
}
|
||||
}
|
||||
|
||||
this.entityData.set(POWER, this.entityData.get(POWER) * 0.99f);
|
||||
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.7f);
|
||||
this.entityData.set(DELTA_X_ROT, this.entityData.get(DELTA_X_ROT) * 0.7f);
|
||||
|
||||
this.setZRot(Mth.clamp(this.getRoll() - this.entityData.get(DELTA_ROT), -30, 30));
|
||||
this.setBodyXRot(Mth.clamp(this.getBodyPitch() - this.entityData.get(DELTA_X_ROT), -30, 30));
|
||||
|
||||
setDeltaMovement(getDeltaMovement().add(0.0f, Math.min(Math.sin((90 - this.getBodyPitch()) * Mth.DEG_TO_RAD), Math.sin((90 + this.getRoll()) * Mth.DEG_TO_RAD)) * this.entityData.get(POWER), 0.0f));
|
||||
setDeltaMovement(getDeltaMovement().add(0.0f, this.entityData.get(POWER) * 0.6f, 0.0f));
|
||||
|
||||
Vector3f direction = getRightDirection().mul(this.entityData.get(DELTA_ROT));
|
||||
setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(0.04)));
|
||||
setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(0.03)));
|
||||
|
||||
Vector3f directionZ = getForwardDirection().mul(-this.entityData.get(DELTA_X_ROT));
|
||||
setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(0.04)));
|
||||
setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(0.03)));
|
||||
|
||||
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
|
||||
if (controller != null) {
|
||||
|
@ -494,6 +502,11 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
return ModSounds.DRONE_SOUND.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEngineSoundVolume() {
|
||||
return onGround() ? 0 : 0.1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(@NotNull MoverType movementType, @NotNull Vec3 movement) {
|
||||
super.move(movementType, movement);
|
||||
|
@ -628,11 +641,6 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
level.addFreshEntity(cloud);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNoGravity() {
|
||||
return super.isNoGravity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
||||
}
|
||||
|
|
|
@ -239,9 +239,7 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
preventStacking();
|
||||
crushEntities(this.getDeltaMovement());
|
||||
|
||||
if (!(this instanceof DroneEntity)) {
|
||||
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.06, 0.0));
|
||||
}
|
||||
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.06, 0.0));
|
||||
|
||||
this.move(MoverType.SELF, this.getDeltaMovement());
|
||||
baseCollideBlock();
|
||||
|
@ -692,9 +690,6 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
|||
public SoundEvent getEngineSound() {
|
||||
return SoundEvents.EMPTY;
|
||||
}
|
||||
public int getEngineSoundRadius() {
|
||||
return 32;
|
||||
}
|
||||
|
||||
public float getEngineSoundVolume() {
|
||||
return (float) Mth.lerp(Mth.clamp(getDeltaMovement().length(), 0F, 0.5F), 0.0F, 0.7F);
|
||||
|
|
|
@ -1,29 +1,15 @@
|
|||
package com.atsuishio.superbwarfare.event;
|
||||
|
||||
import com.atsuishio.superbwarfare.client.LoudlyEntitySoundInstance;
|
||||
import com.atsuishio.superbwarfare.client.VehicleSoundInstance;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.SwarmDroneEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
|
||||
import com.atsuishio.superbwarfare.entity.LoudlyEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.TrackEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import com.atsuishio.superbwarfare.tools.SeekTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||
import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent;
|
||||
import org.joml.Math;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT)
|
||||
public class ClientSoundHandler {
|
||||
|
@ -37,58 +23,11 @@ public class ClientSoundHandler {
|
|||
if (event.getEntity() instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof TrackEntity) {
|
||||
Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.TrackSound(mobileVehicle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handleClientTick(ClientTickEvent.Pre event) {
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
|
||||
List<Entity> engineVehicle = SeekTool.getVehicleWithinRange(player, player.level(), 192);
|
||||
|
||||
for (var e : engineVehicle) {
|
||||
if (e instanceof MobileVehicleEntity mobileVehicle) {
|
||||
|
||||
Vec3 listener = player.getEyePosition();
|
||||
Vec3 engineRealPos = e.getEyePosition();
|
||||
Vec3 toVec = listener.vectorTo(engineRealPos).normalize();
|
||||
double distance = listener.distanceTo(engineRealPos);
|
||||
|
||||
var engineSoundPos = new Vec3(listener.x + toVec.x, listener.y + toVec.y, listener.z + toVec.z);
|
||||
SoundEvent engineSound = mobileVehicle.getEngineSound();
|
||||
float distanceReduce;
|
||||
|
||||
if (e instanceof DroneEntity) {
|
||||
distanceReduce = (float) Math.max((1 - distance / 64), 0);
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
final var tag = NBTTool.getTag(stack);
|
||||
if (stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using")) {
|
||||
player.playSound(engineSound, 1, (float) ((2 * Math.random() - 1) * 0.002f + 1.05));
|
||||
} else {
|
||||
player.level().playLocalSound(BlockPos.containing(engineSoundPos), engineSound, mobileVehicle.getSoundSource(), e.onGround() ? 0 : distanceReduce * distanceReduce, (float) ((2 * Math.random() - 1) * 0.002f + 1.05), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Entity> swarmDrone = SeekTool.getEntityWithinRange(player, player.level(), 64);
|
||||
|
||||
for (var e : swarmDrone) {
|
||||
if (e instanceof SwarmDroneEntity swarmDroneEntity) {
|
||||
|
||||
Vec3 listener = player.getEyePosition();
|
||||
Vec3 engineRealPos = e.getEyePosition();
|
||||
Vec3 toVec = listener.vectorTo(engineRealPos).normalize();
|
||||
double distance = listener.distanceTo(engineRealPos);
|
||||
|
||||
var engineSoundPos = new Vec3(listener.x + toVec.x, listener.y + toVec.y, listener.z + toVec.z);
|
||||
SoundEvent engineSound = ModSounds.DRONE_SOUND.get();
|
||||
float distanceReduce;
|
||||
|
||||
distanceReduce = (float) Math.max((1 - distance / 64), 0);
|
||||
if (swarmDroneEntity.tickCount > 10) {
|
||||
player.level().playLocalSound(BlockPos.containing(engineSoundPos), engineSound, swarmDroneEntity.getSoundSource(), distanceReduce * distanceReduce, (float) ((2 * Math.random() - 1) * 0.002f + 1.15), false);
|
||||
if (event.getEntity() instanceof LoudlyEntity loudlyEntity) {
|
||||
Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySound(event.getEntity()));
|
||||
if (loudlyEntity.getCloseSound() != null) {
|
||||
Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySoundClose(event.getEntity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -441,6 +441,9 @@ public class ModSounds {
|
|||
public static final DeferredHolder<SoundEvent, SoundEvent> HPJ_11_FAR = REGISTRY.register("hpj_11_far", () -> SoundEvent.createVariableRangeEvent(Mod.loc("hpj_11_far")));
|
||||
public static final DeferredHolder<SoundEvent, SoundEvent> HPJ_11_VERYFAR = REGISTRY.register("hpj_11_veryfar", () -> SoundEvent.createVariableRangeEvent(Mod.loc("hpj_11_veryfar")));
|
||||
public static final DeferredHolder<SoundEvent, SoundEvent> TRACK_MOVE = REGISTRY.register("track_move", () -> SoundEvent.createVariableRangeEvent(Mod.loc("track_move")));
|
||||
public static final DeferredHolder<SoundEvent, SoundEvent> ROCKET_FLY = REGISTRY.register("rocket_fly", () -> SoundEvent.createVariableRangeEvent(Mod.loc("rocket_fly")));
|
||||
public static final DeferredHolder<SoundEvent, SoundEvent> SHELL_FLY = REGISTRY.register("shell_fly", () -> SoundEvent.createVariableRangeEvent(Mod.loc("shell_fly")));
|
||||
public static final DeferredHolder<SoundEvent, SoundEvent> ROCKET_ENGINE = REGISTRY.register("rocket_engine", () -> SoundEvent.createVariableRangeEvent(Mod.loc("rocket_engine")));
|
||||
public static final DeferredHolder<SoundEvent, SoundEvent> A_10_ENGINE = REGISTRY.register("a10_engine", () -> SoundEvent.createVariableRangeEvent(Mod.loc("a10_engine")));
|
||||
}
|
||||
|
||||
|
|
|
@ -2186,8 +2186,9 @@
|
|||
"drone_sound": {
|
||||
"sounds": [
|
||||
{
|
||||
"name": "superbwarfare:drone_sound",
|
||||
"stream": false
|
||||
"attenuation_distance": 48,
|
||||
"stream": false,
|
||||
"name": "superbwarfare:drone_sound"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -3072,6 +3073,33 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"rocket_fly": {
|
||||
"sounds": [
|
||||
{
|
||||
"attenuation_distance": 128,
|
||||
"stream": true,
|
||||
"name": "superbwarfare:rocket_fly"
|
||||
}
|
||||
]
|
||||
},
|
||||
"shell_fly": {
|
||||
"sounds": [
|
||||
{
|
||||
"attenuation_distance": 160,
|
||||
"stream": true,
|
||||
"name": "superbwarfare:shell_fly"
|
||||
}
|
||||
]
|
||||
},
|
||||
"rocket_engine": {
|
||||
"sounds": [
|
||||
{
|
||||
"attenuation_distance": 48,
|
||||
"stream": true,
|
||||
"name": "superbwarfare:rocket_engine"
|
||||
}
|
||||
]
|
||||
},
|
||||
"a10_engine": {
|
||||
"sounds": [
|
||||
{
|
||||
|
|
Binary file not shown.
BIN
src/main/resources/assets/superbwarfare/sounds/rocket_engine.ogg
Normal file
BIN
src/main/resources/assets/superbwarfare/sounds/rocket_engine.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/superbwarfare/sounds/rocket_fly.ogg
Normal file
BIN
src/main/resources/assets/superbwarfare/sounds/rocket_fly.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/superbwarfare/sounds/shell_fly.ogg
Normal file
BIN
src/main/resources/assets/superbwarfare/sounds/shell_fly.ogg
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue