载具可被怪物攻击,添加汤姆6的配置项和音效

This commit is contained in:
Atsuihsio 2025-01-25 14:51:55 +08:00
parent 14f11cecdd
commit 750bf8236a
6 changed files with 74 additions and 61 deletions

View file

@ -45,6 +45,12 @@ public class VehicleConfig {
public static ForgeConfigSpec.IntValue LAV_150_CANNON_EXPLOSION_DAMAGE;
public static ForgeConfigSpec.IntValue LAV_150_CANNON_EXPLOSION_RADIUS;
public static ForgeConfigSpec.IntValue TOM_6_HP;
public static ForgeConfigSpec.IntValue TOM_6_MAX_ENERGY;
public static ForgeConfigSpec.IntValue TOM_6_ENERGY_COST;
public static ForgeConfigSpec.IntValue TOM_6_BOMB_EXPLOSION_DAMAGE;
public static ForgeConfigSpec.IntValue TOM_6_BOMB_EXPLOSION_RADIUS;
public static void init(ForgeConfigSpec.Builder builder) {
builder.push("mk_42");
@ -175,6 +181,25 @@ public class VehicleConfig {
LAV_150_CANNON_EXPLOSION_RADIUS = builder.defineInRange("lav_150_cannon_explosion_radius", 3, 1, 10000000);
builder.pop();
builder.push("tom_6");
builder.comment("The HealthPoint of Tom_6");
TOM_6_HP = builder.defineInRange("tom_6_hp", 50, 1, 10000000);
builder.comment("The energy cost of Tom_6 per tick");
TOM_6_ENERGY_COST = builder.defineInRange("tom_6_energy_cost", 16, 0, 2147483647);
builder.comment("The max energy storage of Tom_6");
TOM_6_MAX_ENERGY = builder.defineInRange("tom_6_max_energy", 160000, 0, 2147483647);
builder.comment("The Melon Bomb explosion damage of Tom_6");
TOM_6_BOMB_EXPLOSION_DAMAGE = builder.defineInRange("tom_6_bomb_explosion_damage", 1000, 1, 10000000);
builder.comment("The Melon Bomb explosion radius of Tom_6");
TOM_6_BOMB_EXPLOSION_RADIUS = builder.defineInRange("tom_6_bomb_explosion_radius", 16, 1, 10000000);
builder.pop();
}
}

View file

@ -1,5 +1,6 @@
package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.tools.ProjectileTool;
import net.minecraft.network.protocol.Packet;
@ -46,7 +47,7 @@ public class MelonBombEntity extends ThrowableItemProjectile {
@Override
public void onHitBlock(BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult);
ProjectileTool.causeCustomExplode(this, 1000, 16, 1.5f);
ProjectileTool.causeCustomExplode(this, VehicleConfig.TOM_6_BOMB_EXPLOSION_DAMAGE.get(), VehicleConfig.TOM_6_BOMB_EXPLOSION_RADIUS.get(), 1.5f);
this.discard();
}
@ -56,7 +57,7 @@ public class MelonBombEntity extends ThrowableItemProjectile {
if (tickCount > 600) {
this.discard();
if (!this.level().isClientSide) {
ProjectileTool.causeCustomExplode(this, 1000, 16, 1.5f);
ProjectileTool.causeCustomExplode(this, VehicleConfig.TOM_6_BOMB_EXPLOSION_DAMAGE.get(), VehicleConfig.TOM_6_BOMB_EXPLOSION_RADIUS.get(), 1.5f);
}
}

View file

@ -27,7 +27,6 @@ import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
@ -149,27 +148,9 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
if (source.is(ModDamageTypes.VEHICLE_STRIKE)) {
amount *= 0.7f;
}
if (source.is(DamageTypes.PLAYER_ATTACK)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.MOB_ATTACK)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.MOB_ATTACK_NO_AGGRO)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.MOB_PROJECTILE)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.ARROW)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.TRIDENT)) {
amount *= 0.05f;
}
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
this.hurt(0.5f * Math.max(amount - 15, 0));
this.hurt(0.5f * Math.max(amount - 10, 0));
return true;
}

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.entity.vehicle;
import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig;
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.projectile.MelonBombEntity;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities;
@ -47,8 +48,8 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Boolean> MELON = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.BOOLEAN);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public static final float MAX_HEALTH = 50;
public static final int MAX_ENERGY = 100000;
public static final float MAX_HEALTH = VehicleConfig.TOM_6_HP.get();
public static final int MAX_ENERGY = VehicleConfig.TOM_6_MAX_ENERGY.get();
public Tom6Entity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.TOM_6.get(), world);
@ -114,6 +115,12 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).scale((0.24) * this.getDeltaMovement().length())));
this.setDeltaMovement(this.getDeltaMovement().multiply(f, f, f));
if (onGround()) {
setXRot(getXRot() * 0.7f);
setZRot(getRoll() * 0.7f);
}
this.refreshDimensions();
}
@ -138,11 +145,18 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
this.setDeltaMovement(this.getDeltaMovement().multiply(0.8, 1, 0.8));
}
} else if (passenger instanceof Player player) {
if (level().isClientSide && this.getEnergy() > 0) {
level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.forwardInputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 1.2f), false);
}
// SoundTool.playLocalSound(player, SoundEvents.ELYTRA_FLYING);
if (forwardInputDown && getEnergy() > 0) {
this.extraEnergy(VehicleConfig.TOM_6_ENERGY_COST.get());
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + (entityData.get(MELON) ? 0.003f : 0.0022f), entityData.get(MELON) ? 0.12f : 0.15f));
}
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot()));
if (backInputDown || downInputDown) {
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.006f, onGround() ? -0.12f : 0.04f));
}
if (!onGround()) {
if (rightInputDown) {
@ -152,6 +166,9 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
}
}
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot()));
float roll = Mth.abs(Mth.clamp(getRoll() / 60 , -1.5f , 1.5f));
float addY = Mth.clamp(Math.min((this.onGround() ? 1.5f : 0.9f) * (float) Math.max(getDeltaMovement().length() - 0.06, 0.1), 0.9f) * diffY - 0.5f * this.entityData.get(DELTA_ROT), (entityData.get(MELON) ? -2f : -3f) * (roll + 1), (entityData.get(MELON) ? 2f : 3f) * (roll + 1));
@ -161,6 +178,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
this.setXRot(Mth.clamp(this.getXRot() + addX, onGround() ? -10 : -120, onGround() ? 2 : 120));
this.setZRot(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.01f) * diffY * (float) getDeltaMovement().length());
// 空格投掷西瓜炸弹
if (upInputDown && !onGround() && entityData.get(MELON)) {
entityData.set(MELON, false);
@ -170,33 +188,14 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
MelonBombEntity melonBomb = new MelonBombEntity(player, player.level());
melonBomb.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
melonBomb.shoot(this.getDeltaMovement().x, this.getDeltaMovement().y, this.getDeltaMovement().z, 0.96f * (float)this.getDeltaMovement().length(), 0);
melonBomb.shoot(getDeltaMovement().x, getDeltaMovement().y, getDeltaMovement().z, (float)getDeltaMovement().length(), 0);
passenger.level().addFreshEntity(melonBomb);
this.level().playSound(null, this.getOnPos(), SoundEvents.IRON_DOOR_OPEN, SoundSource.PLAYERS, 1, 1);
this.level().playSound(null, getOnPos(), SoundEvents.IRON_DOOR_OPEN, SoundSource.PLAYERS, 1, 1);
upInputDown = false;
}
}
if (forwardInputDown) {
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + (entityData.get(MELON) ? 0.003f : 0.0022f), entityData.get(MELON) ? 0.12f : 0.15f));
}
if (backInputDown || downInputDown) {
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.006f, onGround() ? -0.12f : 0.04f));
}
if (onGround()) {
setXRot(getXRot() * 0.7f);
setZRot(getRoll() * 0.7f);
} else {
// setZRot(getRoll() * 0.994f);
}
// if (this.forwardInputDown || this.backInputDown) {
// this.extraEnergy(VehicleConfig.SPEEDBOAT_ENERGY_COST.get());
// }
this.entityData.set(POWER, this.entityData.get(POWER) * 0.99f);
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.95f);
@ -205,7 +204,6 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
Mth.clamp(Math.sin((onGround() ? 45 : -(getXRot() - 30)) * Mth.DEG_TO_RAD) * getDeltaMovement().horizontalDistance() * (entityData.get(MELON) ? 0.047f : 0.067f), -0.04, 0.09),
Mth.cos(this.getYRot() * 0.017453292F) * (entityData.get(MELON) ? 0.16f : 0.19f) * this.entityData.get(POWER)
));
}
@Override

View file

@ -8,8 +8,6 @@ import com.atsuishio.superbwarfare.entity.ICustomKnockback;
import com.atsuishio.superbwarfare.entity.TargetEntity;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.entity.vehicle.IArmedVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.ICannonEntity;
import com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity;
import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -57,8 +55,11 @@ public class LivingEventHandler {
@SubscribeEvent
public static void onEntityAttacked(LivingAttackEvent event) {
if (!event.getSource().is(ModDamageTypes.VEHICLE_EXPLOSION) && (event.getEntity().getVehicle() instanceof ICannonEntity || event.getEntity().getVehicle() instanceof Lav150Entity)) {
event.setCanceled(true);
if (!event.getSource().is(ModDamageTypes.VEHICLE_EXPLOSION) && event.getEntity().getVehicle() instanceof VehicleEntity vehicle) {
if (event.getEntity().getVehicle() instanceof IArmedVehicleEntity iArmedVehicle && iArmedVehicle.hidePassenger()) {
vehicle.hurt(event.getSource(),event.getAmount());
event.setCanceled(true);
}
}
}
@ -95,13 +96,16 @@ public class LivingEventHandler {
private static void handleVehicleHurt(LivingHurtEvent event) {
var vehicle = event.getEntity().getVehicle();
if (vehicle != null) {
if (vehicle instanceof ICannonEntity || vehicle instanceof Lav150Entity) {
if (!event.getSource().is(ModDamageTypes.VEHICLE_EXPLOSION)) {
event.setCanceled(true);
if (vehicle instanceof VehicleEntity) {
if (vehicle instanceof IArmedVehicleEntity iArmedVehicle) {
if (iArmedVehicle.hidePassenger()){
if (!event.getSource().is(ModDamageTypes.VEHICLE_EXPLOSION)) {
event.setCanceled(true);
}
} else {
vehicle.hurt(event.getSource(),0.7f * event.getAmount());
event.setAmount(0.3f * event.getAmount());
}
} else if (vehicle instanceof IArmedVehicleEntity) {
event.setAmount(0.3f * event.getAmount());
}
}
}

View file

@ -47,11 +47,15 @@ public class MouseHandlerMixin {
}
if (player.getVehicle() instanceof Lav150Entity) {
return ClientEventHandler.zoomVehicle ? 0.23 : 0.28;
return ClientEventHandler.zoomVehicle ? 0.23 : 0.3;
}
if (player.getVehicle() instanceof Ah6Entity ah6Entity && !ah6Entity.onGround() && ah6Entity.getFirstPassenger() == player) {
return 0.28;
return 0.3;
}
if (player.getVehicle() instanceof Tom6Entity) {
return 0.3;
}
if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) {