Added a Mana HUD.

This commit is contained in:
Vasco Lavos committed 2014-05-25 20:40:05 +01:00
1 parent e31e408a43
commit 371b5ffac3
14 files changed
+174 -10

No files matched your search

@@ -0,0 +1,26 @@
/**
* 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 @ [May 25, 2014, 7:34:00 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
/**
* Have an item implement this to flag it as an infinite
* mana source for the purposes of the HUD rendered when
* an IManaUserItem implementing item is present.
*/
public interface ICreativeManaProvider {
public boolean isCreative(ItemStack stack);
}
@@ -58,5 +58,10 @@ public interface IManaItem {
* Can this item export mana to another item?
*/
public boolean canExportManaToItem(ItemStack stack, ItemStack otherStack);
/**
* If this item simply does not export mana in any have, set this to true.
*/
public boolean isNoExport(ItemStack stack);
}
@@ -0,0 +1,26 @@
/**
* 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 @ [May 25, 2014, 7:32:10 PM (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
/**
* Any item that implements this interface is an item that would use mana
* from the player's inventory. If there's any items in the inventory or
* equipped in either the baubles or armor inventories that implement
* this interface, a mana bar will be rendered.
*/
public interface IManaUsingItem {
public boolean usesMana(ItemStack stack);
}
@@ -34,7 +34,6 @@ public final class ManaItemHandler {
IInventory mainInv = player.inventory;
IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player);
new ArrayList();
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
@@ -80,7 +79,6 @@ public final class ManaItemHandler {
IInventory mainInv = player.inventory;
IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player);
new ArrayList();
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
@@ -124,7 +122,6 @@ public final class ManaItemHandler {
IInventory mainInv = player.inventory;
IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player);
new ArrayList();
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
@@ -175,7 +172,6 @@ public final class ManaItemHandler {
IInventory mainInv = player.inventory;
IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player);
new ArrayList();
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
@@ -17,6 +17,9 @@ import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
@@ -28,10 +31,14 @@ import org.lwjgl.opengl.GL11;
import vazkii.botania.api.lexicon.ILexiconable;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.mana.ICreativeManaProvider;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.api.wand.IWandHUD;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.item.ModItems;
import baubles.common.lib.PlayerHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public final class HUDHandler {
@@ -58,9 +65,77 @@ public final class HUDHandler {
drawLexiconGUI(entry, event.resolution);
}
}
} else if(event.type == ElementType.EXPERIENCE) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
int totalMana = 0;
int totalMaxMana = 0;
boolean anyRequest = false;
boolean creative = false;
IInventory mainInv = player.inventory;
IInventory baublesInv = PlayerHandler.getPlayerBaubles(player);
int invSize = mainInv.getSizeInventory();
int size = invSize;
if(baublesInv != null)
size += baublesInv.getSizeInventory();
for(int i = 0; i < size; i++) {
boolean useBaubles = i >= invSize;
IInventory inv = useBaubles ? baublesInv : mainInv;
ItemStack stack = inv.getStackInSlot(i - (useBaubles ? invSize : 0));
if(stack != null) {
Item item = stack.getItem();
if(item instanceof IManaUsingItem)
anyRequest = anyRequest || ((IManaUsingItem) item).usesMana(stack);
if(item instanceof IManaItem) {
if(!((IManaItem) item).isNoExport(stack)) {
totalMana += ((IManaItem) item).getMana(stack);
totalMaxMana += ((IManaItem) item).getMaxMana(stack);
}
}
if(item instanceof ICreativeManaProvider && ((ICreativeManaProvider) item).isCreative(stack))
creative = true;
}
}
if(anyRequest)
renderManaInvBar(event.resolution, creative, totalMana, totalMaxMana);
}
}
private void renderManaInvBar(ScaledResolution res, boolean hasCreative, int totalMana, int totalMaxMana) {
int width = 182;
int x = res.getScaledWidth() / 2 - width / 2;
int y = res.getScaledHeight() - 29;
if(!hasCreative) {
if(totalMaxMana == 0)
width = 0;
else width *= ((double) totalMana / (double) totalMaxMana);
}
if(width == 0) {
if(totalMana > 0)
width = 1;
else return;
}
Minecraft mc = Minecraft.getMinecraft();
Color color = new Color(Color.HSBtoRGB(0.55F, (float) Math.min(1F, Math.sin(System.currentTimeMillis() / 200D) * 0.5 + 1F), 1F));
GL11.glColor4ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue(), (byte) (255 - color.getRed()));
mc.renderEngine.bindTexture(manaBar);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
RenderHelper.drawTexturedModalRect(x, y, 0, 0, 251, width, 5);
GL11.glDisable(GL11.GL_BLEND);
}
private void drawLexiconGUI(LexiconEntry entry, ScaledResolution res) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
@@ -233,4 +233,9 @@ public class ItemManaMirror extends ItemMod implements IManaItem {
}
@Override
public boolean isNoExport(ItemStack stack) {
return false;
}
}
@@ -23,12 +23,13 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import vazkii.botania.api.mana.ICreativeManaProvider;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibItemNames;
public class ItemManaTablet extends ItemMod implements IManaItem {
public class ItemManaTablet extends ItemMod implements IManaItem, ICreativeManaProvider {
IIcon[] icons;
@@ -150,4 +151,14 @@ public class ItemManaTablet extends ItemMod implements IManaItem {
public boolean canExportManaToItem(ItemStack stack, ItemStack otherStack) {
return true;
}
@Override
public boolean isNoExport(ItemStack stack) {
return false;
}
@Override
public boolean isCreative(ItemStack stack) {
return isStackCreative(stack);
}
}
@@ -105,4 +105,9 @@ public class ItemManaRing extends ItemBauble implements IManaItem {
return true;
}
@Override
public boolean isNoExport(ItemStack stack) {
return false;
}
}
@@ -19,6 +19,7 @@ import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.BotaniaCreativeTab;
@@ -28,7 +29,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemManasteelPick extends ItemPickaxe {
public class ItemManasteelPick extends ItemPickaxe implements IManaUsingItem {
private static final int MANA_PER_DAMAGE = 60;
@@ -78,4 +79,9 @@ public class ItemManasteelPick extends ItemPickaxe {
return par2ItemStack.getItem() == ModItems.manaResource && par2ItemStack.getItemDamage() == 0 ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
}
@Override
public boolean usesMana(ItemStack stack) {
return true;
}
}
@@ -95,7 +95,6 @@ public class ItemTerraPick extends ItemManasteelPick implements IManaItem {
if(isEnabled(par1ItemStack)) {
int level = getLevel(par1ItemStack);
System.out.println(level);
if(level == 0)
setEnabled(par1ItemStack, false);
else if(par3Entity instanceof EntityPlayer && !((EntityPlayer) par3Entity).isSwingInProgress)
@@ -222,4 +221,9 @@ public class ItemTerraPick extends ItemManasteelPick implements IManaItem {
return false;
}
@Override
public boolean isNoExport(ItemStack stack) {
return true;
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
#Wed, 21 May 2014 13:53:26 +0100
#Wed, 21 May 2014 21:31:00 +0100
version=beta
build_number=37
build_number=38
mc_version=1.7.2
mod_name=Botania
dir.repo=./
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

+4
View File
@@ -1,3 +1,7 @@
beta 37
*Fixed a crash with the Mana Enchanter with invalid blocks around.
*Fixed the Band of Mana despawning like normal items.
*Fixed the Band of Mana not having a damage bar.
beta 36
*Added an extra little bit of info to the Terra Shatterer's entry.
*Fixed the Jaded Amaranthus being able to place flowers in running water, basically creating instant farms.
+2 -1
View File
@@ -33,4 +33,5 @@ beta-32=1.7.2
beta-33=1.7.2
beta-34=1.7.2
beta-35=1.7.2
beta-36=1.7.2
beta-36=1.7.2
beta-37=1.7.2