调整充电站判定
This commit is contained in:
parent
80e8fb1409
commit
fed3dcca79
4 changed files with 13 additions and 1 deletions
|
@ -163,7 +163,7 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo
|
||||||
|
|
||||||
List<Entity> entities = this.level.getEntitiesOfClass(Entity.class, new AABB(this.getBlockPos()).inflate(CHARGE_RADIUS));
|
List<Entity> entities = this.level.getEntitiesOfClass(Entity.class, new AABB(this.getBlockPos()).inflate(CHARGE_RADIUS));
|
||||||
entities.forEach(entity -> {
|
entities.forEach(entity -> {
|
||||||
if (entity instanceof IChargeEntity chargeEntity && handler.getEnergyStored() > 0) {
|
if (entity instanceof IChargeEntity chargeEntity && handler.getEnergyStored() > 0 && chargeEntity.canCharge()) {
|
||||||
chargeEntity.charge(Math.min(CHARGE_OTHER_SPEED, handler.getEnergyStored()));
|
chargeEntity.charge(Math.min(CHARGE_OTHER_SPEED, handler.getEnergyStored()));
|
||||||
handler.extractEnergy(Math.min(CHARGE_OTHER_SPEED, handler.getEnergyStored()), false);
|
handler.extractEnergy(Math.min(CHARGE_OTHER_SPEED, handler.getEnergyStored()), false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -524,4 +524,9 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
|
||||||
public void charge(int amount) {
|
public void charge(int amount) {
|
||||||
this.entityData.set(ENERGY, Math.min(this.entityData.get(ENERGY) + amount, CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue()));
|
this.entityData.set(ENERGY, Math.min(this.entityData.get(ENERGY) + amount, CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCharge() {
|
||||||
|
return this.entityData.get(ENERGY) < CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,6 @@ package com.atsuishio.superbwarfare.entity;
|
||||||
public interface IChargeEntity {
|
public interface IChargeEntity {
|
||||||
|
|
||||||
void charge(int amount);
|
void charge(int amount);
|
||||||
|
|
||||||
|
boolean canCharge();
|
||||||
}
|
}
|
||||||
|
|
|
@ -713,6 +713,11 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
||||||
this.entityData.set(ENERGY, Math.min(this.entityData.get(ENERGY) + amount, MAX_ENERGY));
|
this.entityData.set(ENERGY, Math.min(this.entityData.get(ENERGY) + amount, MAX_ENERGY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCharge() {
|
||||||
|
return this.entityData.get(ENERGY) < MAX_ENERGY;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canAddPassenger(Entity pPassenger) {
|
protected boolean canAddPassenger(Entity pPassenger) {
|
||||||
return this.getPassengers().size() < this.getMaxPassengers();
|
return this.getPassengers().size() < this.getMaxPassengers();
|
||||||
|
|
Loading…
Add table
Reference in a new issue