From 354fc36bfe132007b24969c28149ddc49c5cf3c0 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Sat, 25 Jan 2014 20:12:17 +0000 Subject: [PATCH] Added HUD features, also particles, because particles are cool. --- .../botania/api/subtile/SubTileEntity.java | 17 +++++- .../client/core/handler/HUDHandler.java | 42 +++++++++++++++ .../client/core/proxy/ClientProxy.java | 4 ++ .../common/block/BlockSpecialFlower.java | 10 +++- .../block/subtile/SubTileGenerating.java | 54 ++++++++++++++++--- .../subtile/generating/SubTileDaybloom.java | 5 ++ .../common/block/tile/TileSpecialFlower.java | 6 +++ resources/assets/botania/lang/en_US.lang | 6 +++ 8 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 MODSRC/vazkii/botania/client/core/handler/HUDHandler.java diff --git a/MODSRC/vazkii/botania/api/subtile/SubTileEntity.java b/MODSRC/vazkii/botania/api/subtile/SubTileEntity.java index 77a016997..41a4a5884 100644 --- a/MODSRC/vazkii/botania/api/subtile/SubTileEntity.java +++ b/MODSRC/vazkii/botania/api/subtile/SubTileEntity.java @@ -11,6 +11,8 @@ */ package vazkii.botania.api.subtile; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -54,12 +56,16 @@ public class SubTileEntity { */ public void readFromPacketNBT(NBTTagCompound cmp) { } + public String getUnlocalizedName() { + return BotaniaAPI.getSubTileStringMapping(getClass()); + } + /** * Gets the icon for this SubTileEntity, this is a block icon. */ @SideOnly(Side.CLIENT) public Icon getIcon() { - Icon icon = BotaniaAPI.internalHandler.getSubTileIconForName(BotaniaAPI.getSubTileStringMapping(getClass())); + Icon icon = BotaniaAPI.internalHandler.getSubTileIconForName(getUnlocalizedName()); System.out.println(icon); return icon; } @@ -77,4 +83,13 @@ public class SubTileEntity { public LexiconEntry getEntry() { return null; } + + /** + * Called on the client when the block being pointed at is the one with this sub tile. + * Used to render a HUD portraying some data from this sub tile. + */ + @SideOnly(Side.CLIENT) + public void renderHUD(Minecraft mc, ScaledResolution res) { + // NO-OP + } } diff --git a/MODSRC/vazkii/botania/client/core/handler/HUDHandler.java b/MODSRC/vazkii/botania/client/core/handler/HUDHandler.java new file mode 100644 index 000000000..f3eaa391d --- /dev/null +++ b/MODSRC/vazkii/botania/client/core/handler/HUDHandler.java @@ -0,0 +1,42 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 25, 2014, 6:11:10 PM (GMT)] + */ +package vazkii.botania.client.core.handler; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +import net.minecraftforge.event.ForgeSubscribe; +import vazkii.botania.common.item.ModItems; + +public final class HUDHandler { + + @ForgeSubscribe + public void onDrawScreen(RenderGameOverlayEvent.Post event) { + if(event.type == ElementType.ALL) { + Minecraft mc = Minecraft.getMinecraft(); + MovingObjectPosition pos = mc.objectMouseOver; + if(pos != null && mc.thePlayer.getCurrentEquippedItem() != null && mc.thePlayer.getCurrentEquippedItem().itemID == ModItems.twigWand.itemID) { + int id = mc.theWorld.getBlockId(pos.blockX, pos.blockY, pos.blockZ); + if(Block.blocksList[id] != null && Block.blocksList[id] instanceof IHUD) + ((IHUD) Block.blocksList[id]).renderHUD(mc, event.resolution, mc.theWorld, pos.blockX, pos.blockY, pos.blockZ); + } + } + } + + public interface IHUD { + public void renderHUD(Minecraft mc, ScaledResolution res, World world, int x, int y, int z); + } +} diff --git a/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java b/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java index a58133861..fdc3cc0a7 100644 --- a/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java +++ b/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java @@ -13,7 +13,9 @@ package vazkii.botania.client.core.proxy; import net.minecraft.client.Minecraft; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; import vazkii.botania.api.LexiconEntry; +import vazkii.botania.client.core.handler.HUDHandler; import vazkii.botania.client.fx.FXSparkle; import vazkii.botania.client.gui.GuiLexicon; import vazkii.botania.client.gui.GuiLexiconEntry; @@ -34,6 +36,8 @@ public class ClientProxy extends CommonProxy { public void init(FMLInitializationEvent event) { super.init(event); + MinecraftForge.EVENT_BUS.register(new HUDHandler()); + initRenderers(); } diff --git a/MODSRC/vazkii/botania/common/block/BlockSpecialFlower.java b/MODSRC/vazkii/botania/common/block/BlockSpecialFlower.java index 913716c03..20821ed52 100644 --- a/MODSRC/vazkii/botania/common/block/BlockSpecialFlower.java +++ b/MODSRC/vazkii/botania/common/block/BlockSpecialFlower.java @@ -19,6 +19,8 @@ import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockFlower; import net.minecraft.block.ITileEntityProvider; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; @@ -32,6 +34,7 @@ import vazkii.botania.api.ILexiconable; import vazkii.botania.api.ISpecialFlower; import vazkii.botania.api.IWandable; import vazkii.botania.api.LexiconEntry; +import vazkii.botania.client.core.handler.HUDHandler.IHUD; import vazkii.botania.client.core.helper.IconHelper; import vazkii.botania.client.lib.LibRenderIDs; import vazkii.botania.common.block.tile.TileSpecialFlower; @@ -41,7 +44,7 @@ import vazkii.botania.common.lib.LibBlockIDs; import vazkii.botania.common.lib.LibBlockNames; import cpw.mods.fml.common.registry.GameRegistry; -public class BlockSpecialFlower extends BlockFlower implements ISpecialFlower, ITileEntityProvider, IWandable, ILexiconable { +public class BlockSpecialFlower extends BlockFlower implements ISpecialFlower, ITileEntityProvider, IWandable, ILexiconable, IHUD { public static Map icons = new HashMap(); private static String[] subtypes = { @@ -143,4 +146,9 @@ public class BlockSpecialFlower extends BlockFlower implements ISpecialFlower, I return ((TileSpecialFlower) world.getBlockTileEntity(x, y, z)).onWanded(stack, player); } + @Override + public void renderHUD(Minecraft mc, ScaledResolution res, World world, int x, int y, int z) { + ((TileSpecialFlower) world.getBlockTileEntity(x, y, z)).renderHUD(mc, res); + } + } diff --git a/MODSRC/vazkii/botania/common/block/subtile/SubTileGenerating.java b/MODSRC/vazkii/botania/common/block/subtile/SubTileGenerating.java index b93923fe6..2cb3cb10e 100644 --- a/MODSRC/vazkii/botania/common/block/subtile/SubTileGenerating.java +++ b/MODSRC/vazkii/botania/common/block/subtile/SubTileGenerating.java @@ -11,16 +11,25 @@ */ package vazkii.botania.common.block.subtile; +import java.awt.Color; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; + +import org.lwjgl.opengl.GL11; + import vazkii.botania.api.subtile.SubTileEntity; +import vazkii.botania.common.Botania; public class SubTileGenerating extends SubTileEntity { private static final String TAG_MANA = "mana"; int mana; - public int knownMana = 0; + public int knownMana = -1; @Override public void onUpdate() { @@ -29,6 +38,12 @@ public class SubTileGenerating extends SubTileEntity { int delay = getDelayBetweenPassiveGeneration(); if(delay > 0 && supertile.worldObj.getWorldTime() % delay == 0) addMana(1); + + double particleChance = 1F - ((double) mana / (double) getMaxMana()) / 2F; + Color color = new Color(getColor()); + if(Math.random() > particleChance) + Botania.proxy.sparkleFX(supertile.worldObj, supertile.xCoord + 0.3 + Math.random() * 0.5, supertile.yCoord + 0.5 + Math.random() * 0.5, supertile.zCoord + 0.3 + Math.random() * 0.5, (float) color.getRed() / 255F, (float) color.getGreen() / 255F, (float) color.getBlue() / 255F, (float) Math.random(), 5); + } public void addMana(int mana) { @@ -43,16 +58,16 @@ public class SubTileGenerating extends SubTileEntity { public boolean onWanded(EntityPlayer player, ItemStack wand) { knownMana = mana; player.worldObj.playSoundAtEntity(player, "random.orb", 1F, 1F); - - // TODO - if(!player.worldObj.isRemote) - player.addChatMessage("mana: " + knownMana); - + return super.onWanded(player, wand); } public int getMaxMana() { - return 2000; + return 20; + } + + public int getColor() { + return 0xFFFFFF; } @Override @@ -65,4 +80,29 @@ public class SubTileGenerating extends SubTileEntity { mana = cmp.getInteger(TAG_MANA); } + @Override + public void renderHUD(Minecraft mc, ScaledResolution res) { + String name = StatCollector.translateToLocal("tile.botania:flower." + getUnlocalizedName() + ".name"); + int type = 0; + if(knownMana >= 0) { + type = 1; + double percentage = (double) knownMana / (double) getMaxMana() * 100; + if(percentage == 100) + type = 5; + else if(percentage >= 75) + type = 4; + else if(percentage >= 50) + type = 3; + else if(percentage > 0) + type = 2; + } + String filling = StatCollector.translateToLocal("botaniamisc.status" + type); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + int color = 0x66000000 | getColor(); + mc.fontRenderer.drawStringWithShadow(name, res.getScaledWidth() / 2 - mc.fontRenderer.getStringWidth(name) / 2, res.getScaledHeight() / 2 + 10, color); + mc.fontRenderer.drawStringWithShadow(filling, res.getScaledWidth() / 2 - mc.fontRenderer.getStringWidth(filling) / 2, res.getScaledHeight() / 2 + 20, color); + GL11.glDisable(GL11.GL_BLEND); + } + } diff --git a/MODSRC/vazkii/botania/common/block/subtile/generating/SubTileDaybloom.java b/MODSRC/vazkii/botania/common/block/subtile/generating/SubTileDaybloom.java index 82b0ee2b6..f71be1368 100644 --- a/MODSRC/vazkii/botania/common/block/subtile/generating/SubTileDaybloom.java +++ b/MODSRC/vazkii/botania/common/block/subtile/generating/SubTileDaybloom.java @@ -15,4 +15,9 @@ import vazkii.botania.common.block.subtile.SubTileGenerating; public class SubTileDaybloom extends SubTileGenerating { + @Override + public int getColor() { + return 0xFFFF00; + } + } diff --git a/MODSRC/vazkii/botania/common/block/tile/TileSpecialFlower.java b/MODSRC/vazkii/botania/common/block/tile/TileSpecialFlower.java index 90fc36490..2f2e1a5b1 100644 --- a/MODSRC/vazkii/botania/common/block/tile/TileSpecialFlower.java +++ b/MODSRC/vazkii/botania/common/block/tile/TileSpecialFlower.java @@ -11,6 +11,8 @@ */ package vazkii.botania.common.block.tile; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -95,4 +97,8 @@ public class TileSpecialFlower extends TileMod { return subTile.onWanded(player, wand); } + public void renderHUD(Minecraft mc, ScaledResolution res) { + subTile.renderHUD(mc, res); + } + } diff --git a/resources/assets/botania/lang/en_US.lang b/resources/assets/botania/lang/en_US.lang index 05e9bac25..4ddb9249b 100644 --- a/resources/assets/botania/lang/en_US.lang +++ b/resources/assets/botania/lang/en_US.lang @@ -6,6 +6,12 @@ botaniamisc.back=Back botaniamisc.craftingContainer=Returns on Crafting botaniamisc.shapeless=Shapeless Recipe botaniamisc.oredict=Ore Dictionary Recipe +botaniamisc.status0=Unknown Status +botaniamisc.status1=Empty +botaniamisc.status2=Mostly Empty +botaniamisc.status3=Moderately Full +botaniamisc.status4=Almost Full +botaniamisc.status5=Full # BLOCK NAMES tile.botania:flower0.name=Mystical White Flower