mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 11:49:37 +00:00
Added HUD features, also particles, because particles are cool.
This commit is contained in:
1 parent
bdd4458056
commit
354fc36bfe
8 files changed
+135
-9
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. 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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String, Icon> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,4 +15,9 @@ import vazkii.botania.common.block.subtile.SubTileGenerating;
|
||||
|
||||
public class SubTileDaybloom extends SubTileGenerating {
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return 0xFFFF00;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user