调整充电站判定

This commit is contained in:
17146 2024-12-16 16:11:27 +08:00
parent 80e8fb1409
commit fed3dcca79
4 changed files with 13 additions and 1 deletions

View file

@ -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));
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()));
handler.extractEnergy(Math.min(CHARGE_OTHER_SPEED, handler.getEnergyStored()), false);
}

View file

@ -524,4 +524,9 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
public void charge(int amount) {
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();
}
}

View file

@ -3,4 +3,6 @@ package com.atsuishio.superbwarfare.entity;
public interface IChargeEntity {
void charge(int amount);
boolean canCharge();
}

View file

@ -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));
}
@Override
public boolean canCharge() {
return this.entityData.get(ENERGY) < MAX_ENERGY;
}
@Override
protected boolean canAddPassenger(Entity pPassenger) {
return this.getPassengers().size() < this.getMaxPassengers();