添加撞击伤害

This commit is contained in:
Atsuihsio 2024-12-12 15:45:25 +08:00
parent 4558b84e30
commit 68f985227a
18 changed files with 135 additions and 58 deletions

View file

@ -24,7 +24,7 @@ public class SpeedboatModel extends GeoModel<SpeedboatEntity> {
@Override @Override
public ResourceLocation getModelResource(SpeedboatEntity entity) { public ResourceLocation getModelResource(SpeedboatEntity entity) {
return ModUtils.loc("geo/speedboat.geo.json"); return new ResourceLocation(ModUtils.MODID, "geo/speedboat.geo.json");
} }
@Override @Override
@ -42,9 +42,8 @@ public class SpeedboatModel extends GeoModel<SpeedboatEntity> {
rotorSpeed = Mth.lerp(0.1f * times, rotorSpeed, 10 * animatable.getEntityData().get(POWER)); rotorSpeed = Mth.lerp(0.1f * times, rotorSpeed, 10 * animatable.getEntityData().get(POWER));
rotor.setRotZ(rotor.getRotZ() + rotorSpeed); rotor.setRotZ(rotor.getRotZ() + rotorSpeed);
lerpRotY = Mth.lerp(0.5f * times, lerpRotY, animatable.getEntityData().get(POWER) > 0 ? animatable.getEntityData().get(DELTA_ROT) : -animatable.getEntityData().get(DELTA_ROT));
lerpRotY = Mth.lerp(0.5f * times, lerpRotY, animatable.getEntityData().get(DELTA_ROT)); duo.setRotY(0.5f * lerpRotY);
duo.setRotY((animatable.getEntityData().get(POWER) > 0 ? 0.5f : -0.5f) * lerpRotY);
} }
} }

View file

@ -15,8 +15,6 @@ import software.bernie.geckolib.renderer.GeoEntityRenderer;
public class SpeedboatRenderer extends GeoEntityRenderer<SpeedboatEntity> { public class SpeedboatRenderer extends GeoEntityRenderer<SpeedboatEntity> {
public static float lerpRotY = 0f;
public SpeedboatRenderer(EntityRendererProvider.Context renderManager) { public SpeedboatRenderer(EntityRendererProvider.Context renderManager) {
super(renderManager, new SpeedboatModel()); super(renderManager, new SpeedboatModel());
} }

View file

@ -44,6 +44,7 @@ public class KillMessageOverlay {
private static final ResourceLocation BURN = ModUtils.loc("textures/screens/damage_types/burn.png"); private static final ResourceLocation BURN = ModUtils.loc("textures/screens/damage_types/burn.png");
private static final ResourceLocation DRONE = ModUtils.loc("textures/screens/damage_types/drone.png"); private static final ResourceLocation DRONE = ModUtils.loc("textures/screens/damage_types/drone.png");
private static final ResourceLocation LASER = ModUtils.loc("textures/screens/damage_types/laser.png"); private static final ResourceLocation LASER = ModUtils.loc("textures/screens/damage_types/laser.png");
private static final ResourceLocation VEHICLE = ModUtils.loc("textures/screens/damage_types/vehicle_strike.png");
private static final ResourceLocation WORLD_PEACE_STAFF = ModUtils.loc("textures/gun_icon/compat/world_peace_staff.png"); private static final ResourceLocation WORLD_PEACE_STAFF = ModUtils.loc("textures/gun_icon/compat/world_peace_staff.png");
@ -278,6 +279,8 @@ public class KillMessageOverlay {
icon = DRONE; icon = DRONE;
} else if (record.damageType == ModDamageTypes.LASER || record.damageType == ModDamageTypes.LASER_HEADSHOT) { } else if (record.damageType == ModDamageTypes.LASER || record.damageType == ModDamageTypes.LASER_HEADSHOT) {
icon = LASER; icon = LASER;
} else if (record.damageType == ModDamageTypes.VEHICLE_STRIKE) {
icon = VEHICLE;
} else { } else {
icon = GENERIC; icon = GENERIC;
} }

View file

@ -87,11 +87,15 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
public void addAdditionalSaveData(CompoundTag compound) { public void addAdditionalSaveData(CompoundTag compound) {
compound.putFloat("Health", this.entityData.get(HEALTH)); compound.putFloat("Health", this.entityData.get(HEALTH));
compound.putFloat("Energy", this.entityData.get(ENERGY)); compound.putFloat("Energy", this.entityData.get(ENERGY));
compound.putFloat("Power", this.entityData.get(POWER));
compound.putFloat("DeltaRot", this.entityData.get(DELTA_ROT));
} }
@Override @Override
public void readAdditionalSaveData(CompoundTag compound) { public void readAdditionalSaveData(CompoundTag compound) {
this.entityData.set(ENERGY, compound.getFloat("Energy")); this.entityData.set(ENERGY, compound.getFloat("Energy"));
this.entityData.set(POWER, compound.getFloat("Power"));
this.entityData.set(DELTA_ROT, compound.getFloat("DeltaRot"));
if (compound.contains("Health")) { if (compound.contains("Health")) {
this.entityData.set(HEALTH, compound.getFloat("Health")); this.entityData.set(HEALTH, compound.getFloat("Health"));
} else { } else {
@ -109,13 +113,14 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
} }
//TODO 创飞碰到的碰撞箱小于该船的实体且本体速度不会减少太多 //TODO 创飞碰到的碰撞箱小于该船的实体且本体速度不会减少太多
public static boolean canVehicleCollide(Entity pVehicle, Entity pEntity) { public static boolean canVehicleCollide(Entity pVehicle, Entity pEntity) {
return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !pVehicle.isPassengerOfSameVehicle(pEntity); return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !pVehicle.isPassengerOfSameVehicle(pEntity);
} }
@Override @Override
public boolean canBeCollidedWith() { public boolean canBeCollidedWith() {
return super.canBeCollidedWith(); return false;
} }
@Override @Override
@ -212,10 +217,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
// player.displayClientMessage(Component.literal("Angle" + new java.text.DecimalFormat("##.##").format(Mth.abs(90 - (float)calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90)), true); // player.displayClientMessage(Component.literal("Angle" + new java.text.DecimalFormat("##.##").format(Mth.abs(90 - (float)calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90)), true);
// } // }
this.inputLeft = this.getPersistentData().getBoolean("left");
this.inputRight = this.getPersistentData().getBoolean("right");
this.inputUp = this.getPersistentData().getBoolean("forward");
this.inputDown = this.getPersistentData().getBoolean("backward");
double fluidFloat = -0.04; double fluidFloat = -0.04;
@ -223,7 +225,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
if (this.isInWater()) { if (this.isInWater()) {
fluidFloat = -0.025 + 0.05 * getSubmergedHeight(this); fluidFloat = -0.025 + 0.05 * getSubmergedHeight(this);
float f = 0.85f + 0.09f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90; float f = 0.87f + 0.09f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90;
this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.04 * this.getDeltaMovement().length()))); this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.04 * this.getDeltaMovement().length())));
this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.85, f)); this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.85, f));
} else if (this.onGround()) { } else if (this.onGround()) {
@ -255,7 +257,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
crushEntities(this.getDeltaMovement()); crushEntities(this.getDeltaMovement());
} }
collideBlock(); collBlock();
this.refreshDimensions(); this.refreshDimensions();
} }
@ -268,61 +270,75 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
double entitySize = entity.getBbWidth() * entity.getBbHeight(); double entitySize = entity.getBbWidth() * entity.getBbHeight();
double thisSize = this.getBbWidth() * this.getBbHeight(); double thisSize = this.getBbWidth() * this.getBbHeight();
double f = Math.min(entitySize / thisSize, 2); double f = Math.min(entitySize / thisSize, 2);
double f1 = thisSize / entitySize; double f1 = Math.min(thisSize / entitySize, 4);
entity.push(f1 * velAdd.x, f1 * velAdd.y, f1 * velAdd.z); entity.push(f1 * velAdd.x, f1 * velAdd.y, f1 * velAdd.z);
if (!(entity instanceof TargetEntity)) {
this.push(-f * velAdd.x, -f * velAdd.y, -f * velAdd.z); this.push(-f * velAdd.x, -f * velAdd.y, -f * velAdd.z);
}
if (velocity.length() > 0.2 && entity.isAlive()) {
if (!this.level().isClientSide) {
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
}
entity.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger() ), (float) (25 * velocity.length()));
entity.invulnerableTime = 10;
}
} }
} }
public void collideBlock() { public void collBlock() {
AABB aabb = AABB.ofSize(new Vec3(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ()), 5, 2.6, 5); AABB aabb = AABB.ofSize(new Vec3(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ()), 5, 2.6, 5);
BlockPos.betweenClosedStream(aabb).forEach((pos) -> { BlockPos.betweenClosedStream(aabb).forEach((block) -> {
BlockState blockstate = this.level().getBlockState(pos); BlockState blockstate = this.level().getBlockState(block);
if (blockstate.is(Blocks.LILY_PAD)) { if (blockstate.is(Blocks.LILY_PAD)) {
this.level().destroyBlock(pos, true); BlockPos blockPos = BlockPos.containing(new Vec3(block.getX(), block.getY(), block.getY()));
this.level().destroyBlock(blockPos, true);
} }
}); });
} }
private void controlBoat() { private void controlBoat() {
if (this.isVehicle()) {
Entity passenger0 = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0); Entity passenger0 = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
float diffY = 0; float diffY = 0;
diffY = (float) Mth.lerp(0.1 * diffY, diffY, 0); diffY = (float) Mth.lerp(0.1 * diffY, diffY, 0);
if (this.inputUp) { if (this.getPersistentData().getBoolean("forward")) {
this.entityData.set(POWER, this.entityData.get(POWER) + 0.08f); this.entityData.set(POWER, this.entityData.get(POWER) + 0.08f);
} }
if (this.inputDown) { if (this.getPersistentData().getBoolean("backward")) {
this.entityData.set(POWER, this.entityData.get(POWER) - 0.12f); this.entityData.set(POWER, this.entityData.get(POWER) - 0.12f);
if (this.inputLeft) { if (this.getPersistentData().getBoolean("left")) {
diffY = Mth.clamp(diffY + 1f, 0, 5); diffY = Mth.clamp(diffY + 1f, 0, 5);
handleSetDiffY(diffY); handleSetDiffY(diffY);
} else if (this.inputRight) { } else if (this.getPersistentData().getBoolean("right")) {
diffY = Mth.clamp(diffY - 1f, -5, 0); diffY = Mth.clamp(diffY - 1f, -5, 0);
handleSetDiffY(diffY); handleSetDiffY(diffY);
} }
} else { } else {
if (this.inputLeft) { if (this.getPersistentData().getBoolean("left")) {
diffY = Mth.clamp(diffY - 1f, -5, 0); diffY = Mth.clamp(diffY - 1f, -5, 0);
handleSetDiffY(diffY); handleSetDiffY(diffY);
} else if (this.inputRight) { } else if (this.getPersistentData().getBoolean("right")) {
diffY = Mth.clamp(diffY + 1f, 0, 5); diffY = Mth.clamp(diffY + 1f, 0, 5);
handleSetDiffY(diffY); handleSetDiffY(diffY);
} }
} }
if (level().isClientSide) { if (level().isClientSide) {
level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.inputUp || this.inputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 0.7f), false); level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.inputUp || this.inputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 1f), false);
} }
this.entityData.set(POWER, this.entityData.get(POWER) * 0.3f); this.entityData.set(POWER, this.entityData.get(POWER) * 0.3f);
this.flyDist = this.entityData.get(POWER);
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.8f); this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.8f);
if (this.isInWater() || this.isUnderWater()) { if (this.isInWater() || this.isUnderWater()) {
@ -330,7 +346,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).scale(this.entityData.get(POWER)))); this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).scale(this.entityData.get(POWER))));
} }
} }
}
private void handleSetDiffY(float diffY) { private void handleSetDiffY(float diffY) {
this.entityData.set(DELTA_ROT, (float) Mth.clamp(diffY * 1.3 * Math.max(4 * this.getDeltaMovement().length(), 0.5), -2 ,2)); this.entityData.set(DELTA_ROT, (float) Mth.clamp(diffY * 1.3 * Math.max(4 * this.getDeltaMovement().length(), 0.5), -2 ,2));
@ -440,6 +455,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
this.clampRotation(entity); this.clampRotation(entity);
} }
@Override @Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) { public void registerControllers(AnimatableManager.ControllerRegistrar data) {

View file

@ -30,6 +30,7 @@ public class ModDamageTypes {
public static final ResourceKey<DamageType> DRONE_HIT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "drone_hit")); public static final ResourceKey<DamageType> DRONE_HIT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "drone_hit"));
public static final ResourceKey<DamageType> LASER = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser")); public static final ResourceKey<DamageType> LASER = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser"));
public static final ResourceKey<DamageType> LASER_HEADSHOT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser_headshot")); public static final ResourceKey<DamageType> LASER_HEADSHOT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser_headshot"));
public static final ResourceKey<DamageType> VEHICLE_STRIKE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "vehicle_strike"));
public static DamageSource causeGunFireDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) { public static DamageSource causeGunFireDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) {
return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(GUN_FIRE), directEntity, attacker); return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(GUN_FIRE), directEntity, attacker);
@ -83,6 +84,10 @@ public class ModDamageTypes {
return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(LASER_HEADSHOT), directEntity, attacker); return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(LASER_HEADSHOT), directEntity, attacker);
} }
public static DamageSource causeVehicleStrikeDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) {
return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(VEHICLE_STRIKE), directEntity, attacker);
}
private static class DamageMessages extends DamageSource { private static class DamageMessages extends DamageSource {
public DamageMessages(Holder.Reference<DamageType> typeReference) { public DamageMessages(Holder.Reference<DamageType> typeReference) {
super(typeReference); super(typeReference);

View file

@ -344,5 +344,6 @@ public class ModSounds {
public static final RegistryObject<SoundEvent> ANNIHILATOR_RELOAD = REGISTRY.register("annihilator_reload", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "annihilator_reload"))); public static final RegistryObject<SoundEvent> ANNIHILATOR_RELOAD = REGISTRY.register("annihilator_reload", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "annihilator_reload")));
public static final RegistryObject<SoundEvent> BOAT_ENGINE = REGISTRY.register("boat_engine", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "boat_engine"))); public static final RegistryObject<SoundEvent> BOAT_ENGINE = REGISTRY.register("boat_engine", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "boat_engine")));
public static final RegistryObject<SoundEvent> VEHICLE_STRIKE = REGISTRY.register("vehicle_strike", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "vehicle_strike")));
} }

View file

@ -0,0 +1,32 @@
{
"format_version": "1.8.0",
"animations": {
"animation.speedboat.idle": {
"loop": true
},
"animation.speedboat.forward": {
"loop": true,
"animation_length": 0.5,
"bones": {
"Rotor": {
"rotation": {
"0.0": [0, 0, 0],
"0.5": [0, 0, 720]
}
}
}
},
"animation.speedboat.backward": {
"loop": true,
"animation_length": 0.5,
"bones": {
"Rotor": {
"rotation": {
"0.0": [0, 0, 0],
"0.5": [0, 0, -720]
}
}
}
}
}
}

View file

@ -335,6 +335,9 @@
"death.attack.laser_headshot": "%1$s的脑子被激光洞穿了", "death.attack.laser_headshot": "%1$s的脑子被激光洞穿了",
"death.attack.laser_headshot.entity": "%1$s被%2$s用激光射穿了脑袋", "death.attack.laser_headshot.entity": "%1$s被%2$s用激光射穿了脑袋",
"death.attack.laser_headshot.item": "%1$s的脑子被%2$s用%3$s发射的激光洞穿了", "death.attack.laser_headshot.item": "%1$s的脑子被%2$s用%3$s发射的激光洞穿了",
"death.attack.vehicle_strike": "%1$s被创死了",
"death.attack.vehicle_strike.entity": "%1$s被%2$s创死了",
"death.attack.vehicle_strike.item": "%1$s的被%2$s用%3$s创死了",
"entity.superbwarfare.projectile": "Bullet", "entity.superbwarfare.projectile": "Bullet",
"entity.superbwarfare.projectile_mortar_shell": "Mortar Shell", "entity.superbwarfare.projectile_mortar_shell": "Mortar Shell",

View file

@ -335,6 +335,9 @@
"death.attack.laser_headshot": "%1$s的脑子被激光洞穿了", "death.attack.laser_headshot": "%1$s的脑子被激光洞穿了",
"death.attack.laser_headshot.entity": "%1$s被%2$s用激光射穿了脑袋", "death.attack.laser_headshot.entity": "%1$s被%2$s用激光射穿了脑袋",
"death.attack.laser_headshot.item": "%1$s的脑子被%2$s用%3$s发射的激光洞穿了", "death.attack.laser_headshot.item": "%1$s的脑子被%2$s用%3$s发射的激光洞穿了",
"death.attack.vehicle_strike": "%1$s被创死了",
"death.attack.vehicle_strike.entity": "%1$s被%2$s创死了",
"death.attack.vehicle_strike.item": "%1$s的被%2$s用%3$s创死了",
"entity.superbwarfare.projectile": "子弹", "entity.superbwarfare.projectile": "子弹",
"entity.superbwarfare.projectile_mortar_shell": "迫击炮弹", "entity.superbwarfare.projectile_mortar_shell": "迫击炮弹",

View file

@ -2437,5 +2437,13 @@
"stream": false "stream": false
} }
] ]
},
"vehicle_strike": {
"sounds": [
{
"name": "superbwarfare:vehicle_strike",
"stream": false
}
]
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

View file

@ -6,6 +6,7 @@
"superbwarfare:shock", "superbwarfare:shock",
"superbwarfare:cannon_fire", "superbwarfare:cannon_fire",
"superbwarfare:laser", "superbwarfare:laser",
"superbwarfare:laser_headshot" "superbwarfare:laser_headshot",
"superbwarfare:vehicle_strike"
] ]
} }

View file

@ -6,6 +6,7 @@
"superbwarfare:shock", "superbwarfare:shock",
"superbwarfare:cannon_fire", "superbwarfare:cannon_fire",
"superbwarfare:laser", "superbwarfare:laser",
"superbwarfare:laser_headshot" "superbwarfare:laser_headshot",
"superbwarfare:vehicle_strike"
] ]
} }

View file

@ -6,6 +6,7 @@
"superbwarfare:shock", "superbwarfare:shock",
"superbwarfare:cannon_fire", "superbwarfare:cannon_fire",
"superbwarfare:laser", "superbwarfare:laser",
"superbwarfare:laser_headshot" "superbwarfare:laser_headshot",
"superbwarfare:vehicle_strike"
] ]
} }

View file

@ -6,6 +6,7 @@
"superbwarfare:shock", "superbwarfare:shock",
"superbwarfare:cannon_fire", "superbwarfare:cannon_fire",
"superbwarfare:laser", "superbwarfare:laser",
"superbwarfare:laser_headshot" "superbwarfare:laser_headshot",
"superbwarfare:vehicle_strike"
] ]
} }

View file

@ -0,0 +1,5 @@
{
"exhaustion": 0,
"message_id": "vehicle_strike",
"scaling": "never"
}