添加载具能量方法的警告日志
This commit is contained in:
parent
7cd07e224c
commit
49c99568c7
1 changed files with 23 additions and 3 deletions
|
@ -510,25 +510,41 @@ public abstract class VehicleEntity extends Entity implements Container {
|
|||
* @param amount 要消耗的电量
|
||||
*/
|
||||
protected void consumeEnergy(int amount) {
|
||||
if (!this.hasEnergyStorage()) return;
|
||||
if (!this.hasEnergyStorage()) {
|
||||
Mod.LOGGER.warn("Trying to consume energy of vehicle {}, but it has no energy storage", this.getName());
|
||||
return;
|
||||
}
|
||||
this.energyStorage.extractEnergy(amount, false);
|
||||
}
|
||||
|
||||
protected boolean canConsume(int amount) {
|
||||
if (!this.hasEnergyStorage()) return false;
|
||||
if (!this.hasEnergyStorage()) {
|
||||
Mod.LOGGER.warn("Trying to check if can consume energy of vehicle {}, but it has no energy storage", this.getName());
|
||||
return false;
|
||||
}
|
||||
return this.getEnergy() >= amount;
|
||||
}
|
||||
|
||||
public int getEnergy() {
|
||||
if (!this.hasEnergyStorage()) {
|
||||
Mod.LOGGER.warn("Trying to get energy of vehicle {}, but it has no energy storage", this.getName());
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
return this.energyStorage.getEnergyStored();
|
||||
}
|
||||
|
||||
public IEnergyStorage getEnergyStorage() {
|
||||
if (!this.hasEnergyStorage()) {
|
||||
Mod.LOGGER.warn("Trying to get energy storage of vehicle {}, but it has no energy storage", this.getName());
|
||||
}
|
||||
return this.energyStorage;
|
||||
}
|
||||
|
||||
protected void setEnergy(int pEnergy) {
|
||||
if (!this.hasEnergyStorage()) return;
|
||||
if (!this.hasEnergyStorage()) {
|
||||
Mod.LOGGER.warn("Trying to set energy of vehicle {}, but it has no energy storage", this.getName());
|
||||
return;
|
||||
}
|
||||
int targetEnergy = Mth.clamp(pEnergy, 0, this.getMaxEnergy());
|
||||
|
||||
if (targetEnergy > energyStorage.getEnergyStored()) {
|
||||
|
@ -539,6 +555,10 @@ public abstract class VehicleEntity extends Entity implements Container {
|
|||
}
|
||||
|
||||
public int getMaxEnergy() {
|
||||
if (!this.hasEnergyStorage()) {
|
||||
Mod.LOGGER.warn("Trying to get max energy of vehicle {}, but it has no energy storage", this.getName());
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
return data().maxEnergy();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue