允许自定义载具自动扣血比例和扣血量

This commit is contained in:
Light_Quanta 2025-05-25 23:49:40 +08:00
parent 7a73933c27
commit 4b46e33b0f
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 27 additions and 2 deletions

View file

@ -30,6 +30,21 @@ public class DefaultVehicleData {
@SerializedName("RepairMaterialHealAmount") @SerializedName("RepairMaterialHealAmount")
public float repairMaterialHealAmount = 50; public float repairMaterialHealAmount = 50;
/**
* 开始自动扣血时的血量比例
*/
@ServerOnly
@SerializedName("SelfHurtPercent")
public float selfHurtPercent = 0.1F;
/**
* 自动扣血每tick扣血量
*/
@ServerOnly
@SerializedName("SelfHurtAmount")
public float selfHurtAmount = 0.1F;
@SerializedName("MaxEnergy") @SerializedName("MaxEnergy")
public int maxEnergy = 100000; public int maxEnergy = 100000;

View file

@ -9,6 +9,7 @@ import com.google.common.cache.LoadingCache;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags; import net.minecraft.tags.ItemTags;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -85,6 +86,14 @@ public class VehicleData {
} }
} }
public float selfHurtPercent() {
return Mth.clamp(data.selfHurtPercent, 0, 1);
}
public float selfHurtAmount() {
return data.selfHurtAmount;
}
public int maxEnergy() { public int maxEnergy() {
return data.maxEnergy; return data.maxEnergy;
} }

View file

@ -617,9 +617,10 @@ public abstract class VehicleEntity extends Entity {
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
if (this.getHealth() <= 0.1 * this.getMaxHealth()) { var data = data();
if (this.getHealth() <= data.selfHurtPercent() * this.getMaxHealth()) {
// 血量过低时自动扣血 // 血量过低时自动扣血
this.onHurt(0.1f, attacker, false); this.onHurt(data.selfHurtAmount(), attacker, false);
} else { } else {
// 呼吸回血 // 呼吸回血
if (repairCoolDown == 0) { if (repairCoolDown == 0) {