2018-10-13 20:35:18 +02:00
|
|
|
package de.ellpeck.naturesaura.events;
|
|
|
|
|
2018-10-19 14:35:25 +02:00
|
|
|
import baubles.api.BaublesApi;
|
2018-10-14 17:46:00 +02:00
|
|
|
import de.ellpeck.naturesaura.Helper;
|
2018-10-13 20:35:18 +02:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2018-10-20 21:19:08 +02:00
|
|
|
import de.ellpeck.naturesaura.aura.Capabilities;
|
2018-10-14 17:46:00 +02:00
|
|
|
import de.ellpeck.naturesaura.aura.IAuraContainer;
|
2018-10-20 21:19:08 +02:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
|
2018-10-19 14:35:25 +02:00
|
|
|
import de.ellpeck.naturesaura.compat.Compat;
|
2018-10-14 17:46:00 +02:00
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
2018-10-13 20:35:18 +02:00
|
|
|
import de.ellpeck.naturesaura.particles.ParticleHandler;
|
|
|
|
import de.ellpeck.naturesaura.particles.ParticleMagic;
|
2018-10-18 19:08:15 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2018-10-18 19:08:15 +02:00
|
|
|
import net.minecraft.client.gui.Gui;
|
2018-10-14 17:46:00 +02:00
|
|
|
import net.minecraft.client.gui.ScaledResolution;
|
2018-10-18 19:08:15 +02:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
|
|
|
import net.minecraft.client.resources.I18n;
|
2018-10-14 17:46:00 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2018-10-18 19:08:15 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2018-10-14 17:46:00 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-10-18 19:08:15 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2018-10-14 17:46:00 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
|
|
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public class ClientEvents {
|
|
|
|
|
2018-10-20 21:19:08 +02:00
|
|
|
public static final ResourceLocation OVERLAYS = new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/overlays.png");
|
2018-10-18 19:08:15 +02:00
|
|
|
|
2018-10-13 20:35:18 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onDebugRender(RenderGameOverlayEvent.Text event) {
|
2018-10-13 20:45:32 +02:00
|
|
|
if (Minecraft.getMinecraft().gameSettings.showDebugInfo) {
|
2018-10-13 20:35:18 +02:00
|
|
|
String prefix = TextFormatting.GREEN + "[" + NaturesAura.MOD_NAME + "]" + TextFormatting.RESET + " ";
|
|
|
|
List<String> left = event.getLeft();
|
|
|
|
left.add("");
|
|
|
|
left.add(prefix + "PartScrn: " + ParticleHandler.getParticleAmount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onRenderLast(RenderWorldLastEvent event) {
|
|
|
|
ParticleHandler.renderParticles(event.getPartialTicks());
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onTextureStitch(TextureStitchEvent event) {
|
2018-10-13 20:45:32 +02:00
|
|
|
event.getMap().registerSprite(ParticleMagic.TEXTURE);
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onClientTick(ClientTickEvent event) {
|
2018-10-13 20:45:32 +02:00
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2018-10-13 20:35:18 +02:00
|
|
|
if (!mc.isGamePaused()) {
|
|
|
|
ParticleHandler.updateParticles();
|
|
|
|
}
|
|
|
|
if (mc.world == null) {
|
|
|
|
ParticleHandler.clearParticles();
|
|
|
|
}
|
|
|
|
}
|
2018-10-14 17:46:00 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onOverlayRender(RenderGameOverlayEvent.Post event) {
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2018-10-20 21:19:08 +02:00
|
|
|
if (event.getType() == ElementType.ALL) {
|
2018-10-14 17:46:00 +02:00
|
|
|
ScaledResolution res = event.getResolution();
|
|
|
|
if (mc.player != null) {
|
|
|
|
ItemStack stack = mc.player.getHeldItemMainhand();
|
2018-10-20 21:19:08 +02:00
|
|
|
if (mc.currentScreen == null) {
|
|
|
|
if (!stack.isEmpty() && stack.getItem() == ModItems.EYE || Compat.baubles && BaublesApi.isBaubleEquipped(mc.player, ModItems.EYE) >= 0) {
|
|
|
|
int maxAura = 0;
|
|
|
|
int aura = 0;
|
|
|
|
int total = 0;
|
|
|
|
|
|
|
|
for (TileEntity tile : Helper.getTileEntitiesInArea(mc.world, mc.player.getPosition(), 15)) {
|
|
|
|
if (tile.hasCapability(Capabilities.auraContainer, null)) {
|
|
|
|
IAuraContainer container = tile.getCapability(Capabilities.auraContainer, null);
|
|
|
|
if (!container.isArtificial()) {
|
|
|
|
maxAura += container.getMaxAura();
|
|
|
|
aura += container.getStoredAura();
|
|
|
|
total++;
|
|
|
|
}
|
2018-10-14 17:46:00 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-18 19:08:15 +02:00
|
|
|
|
2018-10-20 21:19:08 +02:00
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
mc.getTextureManager().bindTexture(OVERLAYS);
|
|
|
|
|
|
|
|
GlStateManager.color(0.8F, 0.25F, 0.25F);
|
|
|
|
float totalPercentage = total / 1500F;
|
|
|
|
int tHeight = MathHelper.ceil(Math.min(1F, totalPercentage) * 50);
|
|
|
|
if (tHeight < 50)
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(3, 17, 6, 12, 6, 50 - tHeight, 256, 256);
|
|
|
|
if (tHeight > 0)
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(3, 17 + 50 - tHeight, 0, 12 + 50 - tHeight, 6, tHeight, 256, 256);
|
|
|
|
|
|
|
|
GlStateManager.color(0.25F, 0.8F, 0.25F);
|
|
|
|
int aHeight = MathHelper.ceil(aura / (float) maxAura * 50);
|
|
|
|
if (aHeight < 50)
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(12, 17, 6, 12, 6, 50 - aHeight, 256, 256);
|
|
|
|
if (aHeight > 0)
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(12, 17 + 50 - aHeight, 0, 12 + 50 - aHeight, 6, aHeight, 256, 256);
|
|
|
|
|
|
|
|
if (mc.objectMouseOver != null) {
|
|
|
|
BlockPos pos = mc.objectMouseOver.getBlockPos();
|
|
|
|
if (pos != null) {
|
|
|
|
TileEntity tile = mc.world.getTileEntity(pos);
|
|
|
|
if (tile != null && tile.hasCapability(Capabilities.auraContainer, null)) {
|
|
|
|
IAuraContainer container = tile.getCapability(Capabilities.auraContainer, null);
|
|
|
|
|
|
|
|
IBlockState state = mc.world.getBlockState(pos);
|
|
|
|
ItemStack blockStack = state.getBlock().getPickBlock(state, mc.objectMouseOver, mc.world, pos, mc.player);
|
|
|
|
this.drawContainerInfo(container, mc, res, 25, blockStack.getDisplayName());
|
|
|
|
|
|
|
|
if (tile instanceof TileEntityNatureAltar) {
|
|
|
|
ItemStack tileStack = ((TileEntityNatureAltar) tile).getItemHandler(null).getStackInSlot(0);
|
|
|
|
if (!tileStack.isEmpty() && tileStack.hasCapability(Capabilities.auraContainer, null)) {
|
|
|
|
IAuraContainer stackContainer = tileStack.getCapability(Capabilities.auraContainer, null);
|
|
|
|
this.drawContainerInfo(stackContainer, mc, res, 45, tileStack.getDisplayName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-14 17:46:00 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-18 19:08:15 +02:00
|
|
|
|
2018-10-20 21:19:08 +02:00
|
|
|
if (totalPercentage > 1F) {
|
|
|
|
mc.fontRenderer.drawString("+", 3F, 9.5F, 0xBB3333, true);
|
|
|
|
}
|
2018-10-18 19:08:15 +02:00
|
|
|
|
2018-10-20 21:19:08 +02:00
|
|
|
float scale = 0.75F;
|
|
|
|
GlStateManager.scale(scale, scale, scale);
|
|
|
|
mc.fontRenderer.drawString(I18n.format("info." + NaturesAura.MOD_ID + ".aura_in_area"), 3 / scale, 3 / scale, 0xBB3333, true);
|
|
|
|
mc.fontRenderer.drawString(I18n.format("info." + NaturesAura.MOD_ID + ".aura_percentage"), 12 / scale, 10 / scale, 0x33BB33, true);
|
2018-10-18 19:08:15 +02:00
|
|
|
|
2018-10-20 21:19:08 +02:00
|
|
|
GlStateManager.popMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < mc.player.inventory.getSizeInventory(); i++) {
|
|
|
|
ItemStack slot = mc.player.inventory.getStackInSlot(i);
|
|
|
|
if (!slot.isEmpty() && slot.getItem() == ModItems.AURA_CACHE) {
|
|
|
|
IAuraContainer container = slot.getCapability(Capabilities.auraContainer, null);
|
|
|
|
int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80);
|
|
|
|
int x = res.getScaledWidth() / 2 - 173;
|
|
|
|
int y = res.getScaledHeight() - 8;
|
|
|
|
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
int color = container.getAuraColor();
|
|
|
|
GlStateManager.color((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F);
|
|
|
|
mc.getTextureManager().bindTexture(OVERLAYS);
|
|
|
|
if (width < 80)
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(x + width, y, width, 0, 80 - width, 6, 256, 256);
|
|
|
|
if (width > 0)
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 6, width, 6, 256, 256);
|
|
|
|
|
|
|
|
float scale = 0.75F;
|
|
|
|
GlStateManager.scale(scale, scale, scale);
|
|
|
|
String s = slot.getDisplayName();
|
|
|
|
mc.fontRenderer.drawString(s, (x + 80) / scale - mc.fontRenderer.getStringWidth(s), (y - 7) / scale, color, true);
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-10-14 17:46:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-20 21:19:08 +02:00
|
|
|
|
|
|
|
private void drawContainerInfo(IAuraContainer container, Minecraft mc, ScaledResolution res, int yOffset, String name) {
|
|
|
|
int color = container.getAuraColor();
|
|
|
|
GlStateManager.color((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F);
|
|
|
|
|
|
|
|
int x = res.getScaledWidth() / 2 - 40;
|
|
|
|
int y = res.getScaledHeight() / 2 + yOffset;
|
|
|
|
int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80);
|
|
|
|
|
|
|
|
mc.getTextureManager().bindTexture(OVERLAYS);
|
|
|
|
if (width < 80)
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(x + width, y, width, 0, 80 - width, 6, 256, 256);
|
|
|
|
if (width > 0)
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 6, width, 6, 256, 256);
|
|
|
|
|
|
|
|
mc.fontRenderer.drawString(name, x + 40 - mc.fontRenderer.getStringWidth(name) / 2F, y - 9, color, true);
|
|
|
|
}
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|