接着昨天的教程,我们给载具加上一些特殊功能
1.改变载具的声效声音事件教程:
我们把载具的声效.ogg文件进行上面教程的操作,然后将载具的声效进行替换:
在我们的载具类HeisenCarEntity.java中添加:
//飞奔的音效
protected void playGallopSound(SoundType p_190680_1_) {
super.playGallopSound(p_190680_1_);
// if (this.random.nextInt(2) > -1) {
//我们自定义的音效
this.playSound(SoundInit.ENTITY_HEISENCAR_ROLLING.get(), p_190680_1_.getVolume() * 0.6F, p_190680_1_.getPitch());
// }
ItemStack stack = this.inventory.getItem(1);
if (isArmor(stack)) stack.onHorseArmorTick(level, this);
}
//挂机音效
protected SoundEvent getAmbientSound() {
super.getAmbientSound();
return SoundInit.ENTITY_HEISENCAR_ROLLING.get();
}
//载具爆炸损毁音效
protected SoundEvent getDeathSound() {
super.getDeathSound();
return SoundInit.ENTITY_HEISENCAR_FIRING.get();
}
//载具愤怒音效
protected SoundEvent getAngrySound() {
super.getAngrySound();
return SoundInit.ENTITY_HEISENCAR_ROLLING.get();
}
//载具加油音效
@Nullable
protected SoundEvent getEatingSound() {
return SoundInit.ENTITY_HEISENCAR_ROLLING.get();
}
//载具遭到破坏音效
protected SoundEvent getHurtSound(DamageSource p_184601_1_) {
super.getHurtSound(p_184601_1_);
return SoundInit.ENTITY_HEISENCAR_ROLLING.get();
}
//载具运动音效
protected void playStepSound(BlockPos p_180429_1_, BlockState p_180429_2_) {
if (!p_180429_2_.getMaterial().isLiquid()) {
BlockState blockstate = this.level.getBlockState(p_180429_1_.above());
SoundType soundtype = p_180429_2_.getSoundType(level, p_180429_1_, this);
if (blockstate.is(Blocks.SNOW)) {
soundtype = blockstate.getSoundType(level, p_180429_1_, this);
}
if (this.isVehicle() && this.canGallop) {
++this.gallopSoundCounter;
if (this.gallopSoundCounter > 5 && this.gallopSoundCounter % 3 == 0) {
this.playGallopSound(soundtype);
} else if (this.gallopSoundCounter <= 5) {
this.playSound(SoundInit.ENTITY_HEISENCAR_ROLLING.get(), soundtype.getVolume() * 0.15F, soundtype.getPitch());
}
} else if (soundtype == SoundType.WOOD) {
this.playSound(SoundInit.ENTITY_HEISENCAR_ROLLING.get(), soundtype.getVolume() * 0.15F, soundtype.getPitch());
} else {
this.playSound(SoundInit.ENTITY_HEISENCAR_ROLLING.get(), soundtype.getVolume() * 0.15F, soundtype.getPitch());
}
}
}
//载具摔落音效
public boolean causeFallDamage(float p_225503_1_, float p_225503_2_) {
if (p_225503_1_ > 1.0F) {
this.playSound(SoundInit.ENTITY_HEISENCAR_ROLLING.get(), 0.4F, 1.0F);
}
int i = this.calculateFallDamage(p_225503_1_, p_225503_2_);
if (i <= 0) {
return false;
} else {
this.hurt(DamageSource.FALL, (float)i);
if (this.isVehicle()) {
for(Entity entity : this.getIndirectPassengers()) {
entity.hurt(DamageSource.FALL, (float)i);
}
}
this.playBlockFallSound();
return true;
}
}
//载具腾跃音效
protected void playJumpSound() {
this.playSound(SoundInit.ENTITY_HEISENCAR_FIRING.get(), 0.4F, 1.0F);
}
2.增加载具冲撞伤害
在载具类HeisenCarEntity.java添加hurt函数:
private void hurt(List<E

该教程详细介绍了如何在Minecraft模组中增强载具的功能,包括更换载具的声效、增加冲撞伤害、随机爆破效果、开火子弹以及撞飞生物的机制。通过修改载具类的代码,实现了不同场景下的独特音效,以及各种互动行为,如空格键触发的爆炸和射击效果。
最低0.47元/天 解锁文章
3481

被折叠的 条评论
为什么被折叠?



