修复载具上开火把自己弹出的问题

This commit is contained in:
Atsuihsio 2025-01-01 21:47:05 +08:00
parent 974ee5cce1
commit 4247ca342a
10 changed files with 23 additions and 3 deletions

View file

@ -33,7 +33,7 @@ public class EnergyVehicleEntity extends VehicleEntity implements IChargeEntity
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.putFloat("Energy", this.entityData.get(ENERGY));
compound.putInt("Energy", this.entityData.get(ENERGY));
}
public void extraEnergy(int extraAmount) {

View file

@ -71,7 +71,9 @@ public class MobileVehicleEntity extends EnergyVehicleEntity {
double f = Math.min(entitySize / thisSize, 2);
double f1 = Math.min(thisSize / entitySize, 4);
if (entity.isAlive() && !(entity instanceof ItemEntity || entity instanceof Projectile || entity instanceof ProjectileEntity)) {
if (entity.isAlive()
&& !(entity instanceof ItemEntity || entity instanceof Projectile || entity instanceof ProjectileEntity)
&& !(entity instanceof Player player && (player.isSpectator() || player.isCreative()))) {
if (velocity.horizontalDistance() > 0.4) {
if (!this.level().isClientSide) {
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
@ -117,10 +119,12 @@ public class MobileVehicleEntity extends EnergyVehicleEntity {
@Override
protected void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
this.entityData.set(POWER, compound.getFloat("Power"));
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.putFloat("Power", this.entityData.get(POWER));
}
}

View file

@ -6,6 +6,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
@ -21,6 +22,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.joml.Math;
public class VehicleEntity extends Entity {
@ -193,6 +195,11 @@ public class VehicleEntity extends Entity {
return !this.isRemoved();
}
@Override
public boolean skipAttackInteraction(@NotNull Entity attacker) {
return hasPassenger(attacker) || super.skipAttackInteraction(attacker);
}
@Override
public void baseTick() {
super.baseTick();
@ -212,7 +219,7 @@ public class VehicleEntity extends Entity {
handleClientSync();
if (this.getHealth() <= 0) {
if (this.level() instanceof ServerLevel && this.getHealth() <= 0) {
this.ejectPassengers();
destroy();
}

View file

@ -80,6 +80,9 @@ public class GunGrenadeEntity extends ThrowableItemProjectile implements GeoEnti
protected void onHitEntity(EntityHitResult result) {
float damageMultiplier = 1 + this.monsterMultiplier;
Entity entity = result.getEntity();
if (entity == this.getOwner() || entity == this.getVehicle()) return;
if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);

View file

@ -91,6 +91,7 @@ public class HandGrenadeEntity extends ThrowableItemProjectile implements GeoEnt
case ENTITY:
EntityHitResult entityResult = (EntityHitResult) result;
Entity entity = entityResult.getEntity();
if (entity == this.getOwner() || entity == this.getVehicle()) return;
double speed_e = this.getDeltaMovement().length();
if (speed_e > 0.1) {
if (this.getOwner() instanceof LivingEntity living) {

View file

@ -121,6 +121,7 @@ public class JavelinMissileEntity extends ThrowableItemProjectile implements Geo
protected void onHitEntity(EntityHitResult result) {
float damageMultiplier = 1 + this.monsterMultiplier;
Entity entity = result.getEntity();
if (entity == this.getOwner() || entity == this.getVehicle()) return;
if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);

View file

@ -93,6 +93,7 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti
case ENTITY:
EntityHitResult entityResult = (EntityHitResult) result;
Entity entity = entityResult.getEntity();
if (entity == this.getOwner() || entity == this.getVehicle()) return;
if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);

View file

@ -97,6 +97,7 @@ public class RpgRocketEntity extends ThrowableItemProjectile implements GeoEntit
protected void onHitEntity(EntityHitResult result) {
float damageMultiplier = 1 + this.monsterMultiplier;
Entity entity = result.getEntity();
if (entity == this.getOwner() || entity == this.getVehicle()) return;
if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);

View file

@ -79,6 +79,7 @@ public class TaserBulletProjectileEntity extends AbstractArrow implements GeoEnt
@Override
protected void onHitEntity(EntityHitResult result) {
Entity entity = result.getEntity();
if (entity == this.getVehicle()) return;
if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);

View file

@ -31,6 +31,7 @@ public class SeekTool {
&& e != entity
&& e.isAlive()
&& e.getVehicle() == null
&& !(e instanceof Player player && (player.isSpectator()))
&& !(e instanceof ItemEntity || e instanceof ExperienceOrb || e instanceof HangingEntity || e instanceof ProjectileEntity || e instanceof Projectile || e instanceof ArmorStand)
) {
return level.clip(new ClipContext(entity.getEyePosition(), e.getEyePosition(),