允许自定义载具自动扣血比例和扣血量
This commit is contained in:
parent
7a73933c27
commit
4b46e33b0f
3 changed files with 27 additions and 2 deletions
|
@ -30,6 +30,21 @@ public class DefaultVehicleData {
|
|||
@SerializedName("RepairMaterialHealAmount")
|
||||
public float repairMaterialHealAmount = 50;
|
||||
|
||||
/**
|
||||
* 开始自动扣血时的血量比例
|
||||
*/
|
||||
@ServerOnly
|
||||
@SerializedName("SelfHurtPercent")
|
||||
public float selfHurtPercent = 0.1F;
|
||||
|
||||
/**
|
||||
* 自动扣血每tick扣血量
|
||||
*/
|
||||
@ServerOnly
|
||||
@SerializedName("SelfHurtAmount")
|
||||
public float selfHurtAmount = 0.1F;
|
||||
|
||||
|
||||
@SerializedName("MaxEnergy")
|
||||
public int maxEnergy = 100000;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.google.common.cache.LoadingCache;
|
|||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.damagesource.DamageTypes;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
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() {
|
||||
return data.maxEnergy;
|
||||
}
|
||||
|
|
|
@ -617,9 +617,10 @@ public abstract class VehicleEntity extends Entity {
|
|||
|
||||
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 {
|
||||
// 呼吸回血
|
||||
if (repairCoolDown == 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue