use of com.bewitchment.api.capability.IEnergy in project Bewitchment by Um-Mitternacht.
the class EnergyHandler method addEnergy.
/**
* Adds the given value to the energy of the player.
* <p>
* If the amount drained is greater than the available amount,
* it automatically gets stored as overchannel
* </p>
*
* @param player The player
* @param amount The amount
* @return If the amount was greater or equal than 0 and less or equal than the max amount
*/
public static boolean addEnergy(EntityPlayer player, int amount) {
final Optional<IEnergy> optional = getEnergy(player);
boolean mod = false;
if (optional.isPresent()) {
IEnergy energy = optional.get();
mod = energy.set(energy.get() + amount);
energy.tickReset();
if (player instanceof EntityPlayerMP)
energy.syncTo((EntityPlayerMP) player);
}
return mod;
}
use of com.bewitchment.api.capability.IEnergy in project Bewitchment by Um-Mitternacht.
the class EnergyHUD method renderOverlay.
@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
if (event.getType() == RenderGameOverlayEvent.ElementType.HOTBAR && renderTime > 0) {
Minecraft mc = Minecraft.getMinecraft();
TextureManager manager = mc.getTextureManager();
Optional<IEnergy> optional = EnergyHandler.getEnergy(mc.player);
if (optional.isPresent()) {
IEnergy energy = optional.get();
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
ScaledResolution resolution = event.getResolution();
double interpEnergy = 0;
if (oldEnergy >= 0) {
interpEnergy = (double) (energy.get() - oldEnergy) * event.getPartialTicks() + oldEnergy;
} else {
interpEnergy = energy.get();
}
double filled = interpEnergy / energy.getMax();
// System.out.println("fil: " + filled + ", chg: " + energy.get() + ", max: " + energy.getMax());
int height = ConfigHandler.CLIENT.ENERGY_HUD.height;
int width = ConfigHandler.CLIENT.ENERGY_HUD.width;
int x = ConfigHandler.CLIENT.ENERGY_HUD.x;
int y = resolution.getScaledHeight() - ConfigHandler.CLIENT.ENERGY_HUD.y;
if (ConfigHandler.CLIENT.ENERGY_HUD.hide) {
GlStateManager.color(1F, 1F, 1F, visible);
}
double barWidth = width * 7 / 25;
GlStateManager.disableCull();
manager.bindTexture(ResourceLocations.ENERGY_BACKGROUND[0]);
renderTexture(x + 9, y + 88, barWidth, -(height - 28D) * filled, 0, filled);
if (visible == 1f) {
GlStateManager.pushMatrix();
GlStateManager.color(1F, 1F, 1F, visible == 1F ? barAlpha : visible);
manager.bindTexture(ResourceLocations.ENERGY_BACKGROUND[1]);
renderTexture(x + 9, y + 88, barWidth, -(height - 28D) * filled, 0, filled);
GlStateManager.enableCull();
GlStateManager.popMatrix();
}
if (ConfigHandler.CLIENT.ENERGY_HUD.hide) {
GlStateManager.color(1F, 1F, 1F, visible);
}
manager.bindTexture(energy.getType().getTexture());
renderTexture(x, y, width, height, 0, 1);
int textColor = 0x990066;
if (ConfigHandler.CLIENT.ENERGY_HUD.hide) {
int alpha = (int) (visible * 255);
textColor = alpha << 24 | 0x990066;
}
String text = "E: " + energy.get();
mc.fontRenderer.drawStringWithShadow(text, x, y - 10, textColor);
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
}
use of com.bewitchment.api.capability.IEnergy in project Bewitchment by Um-Mitternacht.
the class RitualInfusion method onFinish.
@Override
public void onFinish(EntityPlayer player, TileEntity tile, World world, BlockPos pos, NBTTagCompound data) {
if (player == null) {
return;
}
Optional<IEnergy> eng = EnergyHandler.getEnergy(player);
if (eng.isPresent()) {
IEnergy ien = eng.get();
ien.setType(type);
if (player instanceof EntityPlayerMP)
ien.syncTo((EntityPlayerMP) player);
}
}
use of com.bewitchment.api.capability.IEnergy in project Bewitchment by Um-Mitternacht.
the class EnergyHUD method onTick.
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.END && Minecraft.getMinecraft().player != null) {
Optional<IEnergy> optional = EnergyHandler.getEnergy(Minecraft.getMinecraft().player);
if (optional.isPresent()) {
IEnergy energy = optional.get();
if (lastPulsed > 0)
lastPulsed--;
boolean energyChanged = (oldEnergy != energy.get());
if (energyChanged)
shouldPulse = lastPulsed == 0;
if (energyChanged || isItemEnergyUsing()) {
oldEnergy = energy.get();
renderTime = 60;
visible = 1F;
}
if (renderTime > 0 && energy.get() == energy.getMax()) {
if (ConfigHandler.CLIENT.ENERGY_HUD.hide && renderTime < 20) {
visible -= 0.05F;
visible = MathHelper.clamp(visible, 0F, 1F);
}
renderTime--;
}
if (shouldPulse) {
if (!reverse) {
barAlpha += 0.15F;
if (barAlpha > 1F) {
barAlpha = 1F;
reverse = true;
}
} else {
barAlpha -= 0.15F;
if (barAlpha < 0F) {
barAlpha = 0;
reverse = false;
shouldPulse = false;
lastPulsed = 40;
}
}
}
}
}
}
use of com.bewitchment.api.capability.IEnergy in project Bewitchment by Um-Mitternacht.
the class CommandIncantation method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 1)
throw new WrongUsageException("commands.incantation.usage");
if (sender.getCommandSenderEntity() == null)
return;
final String command = args[0];
if (ModIncantations.getCommands().containsKey(command)) {
IIncantation incantation = ModIncantations.getCommands().get(command);
if (sender.getCommandSenderEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) sender.getCommandSenderEntity();
Optional<IEnergy> ienopt = EnergyHandler.getEnergy(player);
if (ienopt.isPresent()) {
if (ienopt.get().get() >= incantation.getCost()) {
EnergyHandler.addEnergy(player, -incantation.getCost());
incantation.cast(player, args);
} else {
throw new CommandException("commands.incantation.no_energy", sender.getName());
}
} else {
throw new CommandException("commands.incantation.no_energy", sender.getName());
}
}
} else {
throw new CommandException("commands.incantation.notFound", sender.getName());
}
}
Aggregations