Added abilities to the mana tools.

This commit is contained in:
Lizbeth Rika committed 2015-01-23 22:23:44 +00:00
1 parent 8a6a592885
commit 0d5a12ccf2
8 files changed
+183 -2

No files matched your search

@@ -40,6 +40,7 @@ public class ClientTickHandler {
if(event.phase == Phase.END) {
LightningBolt.update();
RedStringRenderer.tick();
ItemsRemainingRenderHandler.tick();
if(Minecraft.getMinecraft().theWorld == null)
ManaNetworkHandler.instance.clear();
@@ -140,6 +140,8 @@ public final class HUDHandler {
profiler.endStartSection("bossBar");
BossBarHandler.render(event.resolution);
profiler.endStartSection("itemsRemaining");
ItemsRemainingRenderHandler.render(event.resolution, event.partialTicks);
profiler.endSection();
profiler.endSection();
@@ -290,7 +292,7 @@ public final class HUDHandler {
GL11.glColor4f(1F, 1F, 1F, 1F);
profiler.endSection();
}
public static void drawSimpleManaHUD(int color, int mana, int maxMana, String name, ScaledResolution res) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
@@ -0,0 +1,99 @@
/**
* 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 23, 2015, 9:22:10 PM (GMT)]
*/
package vazkii.botania.client.core.handler;
import java.util.regex.Pattern;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public final class ItemsRemainingRenderHandler {
private static int maxTicks = 30;
private static int leaveTicks = 20;
private static ItemStack stack;
private static int ticks, count;
@SideOnly(Side.CLIENT)
public static void render(ScaledResolution resolution, float partTicks) {
if(ticks > 0) {
int pos = maxTicks - ticks;
Minecraft mc = Minecraft.getMinecraft();
int x = resolution.getScaledWidth() / 2 + 10 + Math.max(0, pos - leaveTicks);
int y = resolution.getScaledHeight() / 2;
int start = maxTicks - leaveTicks;
float alpha = (ticks + partTicks) > start ? 1F : (float) (ticks + partTicks) / (float) start;
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1F, 1F, 1F, alpha);
RenderHelper.enableGUIStandardItemLighting();
int xp = x + (int) (16F * (1F - alpha));
GL11.glTranslatef(xp, y, 0F);
GL11.glScalef(alpha, 1F, 1F);
RenderItem.getInstance().renderItemAndEffectIntoGUI(mc.fontRenderer, mc.renderEngine, stack, 0, 0);
GL11.glScalef(1F / alpha,1F, 1F);
GL11.glTranslatef(-xp, -y, 0F);
RenderHelper.disableStandardItemLighting();
GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(1F, 1F, 1F, 1F);
int max = stack.getMaxStackSize();
int stacks = count / max;
int rem = count % max;
int color = 0x00FFFFFF | ((int) (alpha * 0xFF) << 24);
if(stacks == 0)
mc.fontRenderer.drawStringWithShadow("" + count, x + 20, y + 6, color);
else mc.fontRenderer.drawStringWithShadow(count + " (" + stacks + "*" + max + "+" + rem + ")", x + 20, y + 6, color);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
}
}
@SideOnly(Side.CLIENT)
public static void tick() {
if(ticks > 0)
--ticks;
}
public static void set(ItemStack stack, int count) {
ItemsRemainingRenderHandler.stack = stack;
ItemsRemainingRenderHandler.count = count;
ticks = maxTicks;
}
public static void set(EntityPlayer player, ItemStack displayStack, Pattern pattern) {
int count = 0;
for(int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stack = player.inventory.getStackInSlot(i);
if(stack != null && pattern.matcher(stack.getUnlocalizedName()).find())
count += stack.stackSize;
}
set(displayStack, count);
}
}
@@ -11,11 +11,14 @@
*/
package vazkii.botania.common.item.equipment.tool.manasteel;
import java.util.regex.Pattern;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
@@ -23,6 +26,7 @@ import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.client.core.handler.ItemsRemainingRenderHandler;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.BotaniaCreativeTab;
@@ -35,6 +39,8 @@ import cpw.mods.fml.relauncher.SideOnly;
public class ItemManasteelAxe extends ItemAxe implements IManaUsingItem {
private static final Pattern SAPLING_PATTERN = Pattern.compile("(?:(?:(?:[A-Z-_.:]|^)sapling)|(?:(?:[a-z-_.:]|^)Sapling))(?:[A-Z-_.:]|$)");
private static final int MANA_PER_DAMAGE = 60;
public ItemManasteelAxe() {
@@ -77,6 +83,21 @@ public class ItemManasteelAxe extends ItemAxe implements IManaUsingItem {
return true;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int s, float sx, float sy, float sz) {
for(int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stackAt = player.inventory.getStackInSlot(i);
if(stackAt != null && SAPLING_PATTERN.matcher(stackAt.getItem().getUnlocalizedName()).find()) {
boolean did = stackAt.getItem().onItemUse(stackAt, player, world, x, y, z, s, sx, sy, sz);
ItemsRemainingRenderHandler.set(player, new ItemStack(Blocks.sapling), SAPLING_PATTERN);
return did;
}
}
return false;
}
@Override
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5) {
@@ -11,11 +11,14 @@
*/
package vazkii.botania.common.item.equipment.tool.manasteel;
import java.util.regex.Pattern;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
@@ -23,6 +26,7 @@ import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.client.core.handler.ItemsRemainingRenderHandler;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.BotaniaCreativeTab;
@@ -35,6 +39,8 @@ import cpw.mods.fml.relauncher.SideOnly;
public class ItemManasteelPick extends ItemPickaxe implements IManaUsingItem {
private static final Pattern TORCH_PATTERN = Pattern.compile("(?:(?:(?:[A-Z-_.:]|^)torch)|(?:(?:[a-z-_.:]|^)Torch))(?:[A-Z-_.:]|$)");
private static final int MANA_PER_DAMAGE = 60;
public ItemManasteelPick() {
@@ -77,6 +83,20 @@ public class ItemManasteelPick extends ItemPickaxe implements IManaUsingItem {
return true;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int s, float sx, float sy, float sz) {
for(int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stackAt = player.inventory.getStackInSlot(i);
if(stackAt != null && TORCH_PATTERN.matcher(stackAt.getItem().getUnlocalizedName()).find()) {
boolean did = stackAt.getItem().onItemUse(stackAt, player, world, x, y, z, s, sx, sy, sz);
ItemsRemainingRenderHandler.set(player, new ItemStack(Blocks.torch), TORCH_PATTERN);
return did;
}
}
return false;
}
public int getManaPerDmg() {
return MANA_PER_DAMAGE;
@@ -16,10 +16,13 @@ import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.api.mana.ManaItemHandler;
@@ -29,6 +32,7 @@ import vazkii.botania.common.core.BotaniaCreativeTab;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.item.equipment.tool.ToolCommons;
import vazkii.botania.common.lib.LibItemNames;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -78,6 +82,39 @@ public class ItemManasteelShovel extends ItemSpade implements IManaUsingItem {
return true;
}
@Override
public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World p_77648_3_, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) {
if(!p_77648_2_.canPlayerEdit(p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_1_))
return false;
else {
UseHoeEvent event = new UseHoeEvent(p_77648_2_, p_77648_1_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_);
if(MinecraftForge.EVENT_BUS.post(event))
return false;
if(event.getResult() == Result.ALLOW) {
ToolCommons.damageItem(p_77648_1_, 1, p_77648_2_, MANA_PER_DAMAGE);
return true;
}
Block block = p_77648_3_.getBlock(p_77648_4_, p_77648_5_, p_77648_6_);
if(p_77648_7_ != 0 && p_77648_3_.getBlock(p_77648_4_, p_77648_5_ + 1, p_77648_6_).isAir(p_77648_3_, p_77648_4_, p_77648_5_ + 1, p_77648_6_) && (block == Blocks.grass || block == Blocks.dirt)) {
Block block1 = Blocks.farmland;
p_77648_3_.playSoundEffect((double)((float)p_77648_4_ + 0.5F), (double)((float)p_77648_5_ + 0.5F), (double)((float)p_77648_6_ + 0.5F), block1.stepSound.getStepResourcePath(), (block1.stepSound.getVolume() + 1.0F) / 2.0F, block1.stepSound.getPitch() * 0.8F);
if (p_77648_3_.isRemote)
return true;
else {
p_77648_3_.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, block1);
ToolCommons.damageItem(p_77648_1_, 1, p_77648_2_, MANA_PER_DAMAGE);
return true;
}
}
return false;
}
}
@Override
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5) {
if(!world.isRemote && player instanceof EntityPlayer && stack.getItemDamage() > 0 && ManaItemHandler.requestManaExact(stack, (EntityPlayer) player, MANA_PER_DAMAGE * 2, true))
@@ -507,7 +507,7 @@ public final class LexiconData {
terraformRod.setLexiconPages(new PageText("0"), new PageText("1"), new PageText("2"), new PageCraftingRecipe("3", ModCraftingRecipes.recipeTerraformRod));
manasteelGear = new BLexiconEntry(LibLexicon.TOOL_MANASTEEL_GEAR, categoryTools);
manasteelGear.setLexiconPages(new PageText("0"), new PageCraftingRecipe("1", ModCraftingRecipes.recipeManasteelPick), new PageCraftingRecipe("2", ModCraftingRecipes.recipeManasteelShovel), new PageCraftingRecipe("3", ModCraftingRecipes.recipeManasteelAxe),
manasteelGear.setLexiconPages(new PageText("0"), new PageText("10"), new PageCraftingRecipe("1", ModCraftingRecipes.recipeManasteelPick), new PageCraftingRecipe("2", ModCraftingRecipes.recipeManasteelShovel), new PageCraftingRecipe("3", ModCraftingRecipes.recipeManasteelAxe),
new PageCraftingRecipe("4", ModCraftingRecipes.recipeManasteelShears), new PageCraftingRecipe("5", ModCraftingRecipes.recipeManasteelSword),
new PageCraftingRecipe("6", ModCraftingRecipes.recipeManasteelHelm), new PageCraftingRecipe("7", ModCraftingRecipes.recipeManasteelChest), new PageCraftingRecipe("8", ModCraftingRecipes.recipeManasteelLegs), new PageCraftingRecipe("9", ModCraftingRecipes.recipeManasteelBoots));