use of com.bewitchment.api.capability.IEnergy in project Bewitchment by Um-Mitternacht.
the class EnergyEvents method onWorldJoin.
@SubscribeEvent
public void onWorldJoin(EntityJoinWorldEvent event) {
if (event.getEntity() instanceof EntityPlayerMP) {
EntityPlayerMP entity = (EntityPlayerMP) event.getEntity();
Optional<IEnergy> optional = EnergyHandler.getEnergy(entity);
optional.ifPresent(iEnergy -> iEnergy.syncTo(entity));
}
}
use of com.bewitchment.api.capability.IEnergy in project Bewitchment by Um-Mitternacht.
the class EnergyEvents method onPlayerClone.
@SuppressWarnings("ConstantConditions")
@SubscribeEvent
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
final EntityPlayer oldPlayer = event.getOriginal();
final EntityPlayer newPlayer = event.getEntityPlayer();
if (event.isWasDeath() && oldPlayer.hasCapability(EnergyProvider.ENERGY_CAPABILITY, null) && newPlayer.hasCapability(EnergyProvider.ENERGY_CAPABILITY, null)) {
final IEnergy oldCap = oldPlayer.getCapability(EnergyProvider.ENERGY_CAPABILITY, null);
final IEnergy newCap = oldPlayer.getCapability(EnergyProvider.ENERGY_CAPABILITY, null);
newCap.set(oldCap.get());
newCap.setMax(oldCap.getMax());
newCap.setRegen(oldCap.getRegenTime(), oldCap.getRegenBurst());
newCap.setUses(oldCap.getUses());
}
}
use of com.bewitchment.api.capability.IEnergy in project Bewitchment by Um-Mitternacht.
the class EnergyEvents method playerUpdate.
@SubscribeEvent
public void playerUpdate(LivingEvent.LivingUpdateEvent event) {
if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityPlayerMP) {
final EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
final Optional<IEnergy> optional = EnergyHandler.getEnergy(player);
if (optional.isPresent()) {
final IEnergy energy = optional.get();
energyRegen(player, energy);
}
}
}
Aggregations