summaryrefslogtreecommitdiff
path: root/common/darkknight/jewelrycraft/item/ItemRing.java
diff options
context:
space:
mode:
authorOnyxDarkKnight <sor1n.iliutza16@gmail.com>2013-12-23 22:03:06 +0200
committerOnyxDarkKnight <sor1n.iliutza16@gmail.com>2013-12-23 22:03:06 +0200
commit198677e5b01009a65d243da1d25a14f879df659c (patch)
tree512da4c4fbccc40fdcfc79a6f6cbf0f4eb0efd50 /common/darkknight/jewelrycraft/item/ItemRing.java
parentb01cf1aa1d3480ad52ee7940f213596bfe6a2090 (diff)
Changed lots of stuff, added new features. Ender Rings!!!
Diffstat (limited to 'common/darkknight/jewelrycraft/item/ItemRing.java')
-rw-r--r--common/darkknight/jewelrycraft/item/ItemRing.java210
1 files changed, 150 insertions, 60 deletions
diff --git a/common/darkknight/jewelrycraft/item/ItemRing.java b/common/darkknight/jewelrycraft/item/ItemRing.java
index 3368032..268a6aa 100644
--- a/common/darkknight/jewelrycraft/item/ItemRing.java
+++ b/common/darkknight/jewelrycraft/item/ItemRing.java
@@ -8,66 +8,118 @@ import javax.imageio.ImageIO;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+import darkknight.jewelrycraft.util.JewelryNBT;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.client.resources.ResourceManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
public class ItemRing extends ItemBase
{
+ public Icon jewel;
+ private int amplifier;
+
public ItemRing(int par1)
{
super(par1);
this.setMaxStackSize(1);
}
+ public void registerIcons(IconRegister iconRegister)
+ {
+ itemIcon = iconRegister.registerIcon("jewelrycraft:ring");
+ jewel = iconRegister.registerIcon("jewelrycraft:jewel");
+ }
+
+ public Icon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
+ {
+ if (stack.hasTagCompound() && stack.getTagCompound().hasKey("jewel")) return getIcon(stack, 1);
+ return getIcon(stack, 0);
+ }
+
+ @Override
+ public Icon getIconFromDamageForRenderPass(int damage, int pass)
+ {
+ return pass == 0 ? super.getIconFromDamageForRenderPass(damage, pass) : jewel;
+ }
+
+ @Override
+ public boolean requiresMultipleRenderPasses()
+ {
+ return true;
+ }
+
@SideOnly(Side.CLIENT)
- public int getColorFromItemStack(ItemStack par1ItemStack, int par2)
+ public int getColorFromItemStack(ItemStack par1ItemStack, int pass)
{
try
{
- return color(par1ItemStack);
+ if(par1ItemStack != null) return color(par1ItemStack, pass);
}
catch (IOException e)
{
e.printStackTrace();
}
- return 0;
+ return 16777215;
}
- public static int color(ItemStack stack) throws IOException
+ public static int color(ItemStack stack, int pass) throws IOException
{
- if (stack.hasTagCompound())
+ if (pass == 0 && stack.hasTagCompound() && stack.getTagCompound().hasKey("ingot"))
{
- if (stack.getTagCompound().hasKey("ingot"))
+ NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot");
+ ItemStack ingotStack = new ItemStack(0, 0, 0);
+ ingotStack.readFromNBT(ingotNBT);
+ if(ingotStack.getIconIndex().getIconName() != "")
{
- NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot");
- ItemStack ingotStack = new ItemStack(0, 0, 0);
- ingotStack.readFromNBT(ingotNBT);
- if(ingotStack.getIconIndex().getIconName() != "")
- {
- String domain = "";
- if(ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1) != "")
- domain = ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1).replace(":", " ").trim();
- else
- domain = "minecraft";
- String texture = ingotStack.getIconIndex().getIconName().substring(ingotStack.getIconIndex().getIconName().lastIndexOf(":") + 1) + ".png";
- ResourceLocation lava = new ResourceLocation(domain, "textures/items/" + texture);
- ResourceManager rm = Minecraft.getMinecraft().getResourceManager();
- BufferedImage bufferedimage = ImageIO.read(rm.getResource(lava).getInputStream());
- return bufferedimage.getRGB(8, 8);
- }
+ String domain = "";
+ if(ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1) != "")
+ domain = ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1).replace(":", " ").trim();
+ else
+ domain = "minecraft";
+ String texture = ingotStack.getIconIndex().getIconName().substring(ingotStack.getIconIndex().getIconName().lastIndexOf(":") + 1) + ".png";
+ ResourceLocation ingot = null;
+ if(ingotStack.getUnlocalizedName().contains("item")) ingot = new ResourceLocation(domain, "textures/items/" + texture);
+ else ingot = new ResourceLocation(domain, "textures/blocks/" + texture);
+ ResourceManager rm = Minecraft.getMinecraft().getResourceManager();
+ BufferedImage bufferedimage = ImageIO.read(rm.getResource(ingot).getInputStream());
+ return bufferedimage.getRGB(9, 9);
}
}
- return 0;
+ if (pass == 1 && stack.hasTagCompound() && stack.getTagCompound().hasKey("jewel"))
+ {
+ NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel");
+ ItemStack ingotStack = new ItemStack(0, 0, 0);
+ ingotStack.readFromNBT(ingotNBT);
+ if(ingotStack != null && ingotStack != new ItemStack(0, 0, 0) && ingotStack.getIconIndex().getIconName() != "")
+ {
+ String domain = "";
+ if(ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1) != "")
+ domain = ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1).replace(":", " ").trim();
+ else
+ domain = "minecraft";
+ String texture = ingotStack.getIconIndex().getIconName().substring(ingotStack.getIconIndex().getIconName().lastIndexOf(":") + 1) + ".png";
+ ResourceLocation jewel = null;
+ if(ingotStack.getUnlocalizedName().contains("item")) jewel = new ResourceLocation(domain, "textures/items/" + texture);
+ else jewel = new ResourceLocation(domain, "textures/blocks/" + texture);
+ ResourceManager rm = Minecraft.getMinecraft().getResourceManager();
+ BufferedImage bufferedimage = ImageIO.read(rm.getResource(jewel).getInputStream());
+ return bufferedimage.getRGB(9, 4);
+ }
+ }
+ return 16777215;
}
public String getItemDisplayName(ItemStack stack)
@@ -85,34 +137,35 @@ public class ItemRing extends ItemBase
return ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim();
}
- public static void addMetal(ItemStack item, ItemStack metal)
+ public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
- NBTTagCompound itemStackData;
- if (item.hasTagCompound())
- itemStackData = item.getTagCompound();
- else
- {
- itemStackData = new NBTTagCompound();
- item.setTagCompound(itemStackData);
- }
- NBTTagCompound ingotNBT = new NBTTagCompound();
- metal.writeToNBT(ingotNBT);
- itemStackData.setTag("ingot", ingotNBT);
- }
-
- public static void addEffect(ItemStack item, int potion)
- {
- NBTTagCompound itemStackData;
- if (item.hasTagCompound())
- itemStackData = item.getTagCompound();
- else
+ if (stack.hasTagCompound())
{
- itemStackData = new NBTTagCompound();
- item.setTagCompound(itemStackData);
+ if(stack.getTagCompound().hasKey("x") && stack.getTagCompound().hasKey("y") && stack.getTagCompound().hasKey("z"))
+ {
+ NBTTagCompound x = (NBTTagCompound) stack.getTagCompound().getTag("x");
+ NBTTagCompound y = (NBTTagCompound) stack.getTagCompound().getTag("y");
+ NBTTagCompound z = (NBTTagCompound) stack.getTagCompound().getTag("z");
+ double posX = 0, posY = 0, posZ = 0;
+ posX = x.getDouble("x");
+ posY = y.getDouble("y");
+ posZ = z.getDouble("z");
+ for(int i = 1; i <= 20; i++)
+ world.spawnParticle("largesmoke", player.posX - 0.5D + Math.random(), player.posY - 1.5D + Math.random(), player.posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D);
+ player.setPositionAndUpdate(posX, posY, posZ);
+ for(int i = 1; i <= 300; i++)
+ world.spawnParticle("portal", posX - 0.5D + Math.random(), posY + Math.random(), posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D);
+ }
+ if(stack.getTagCompound().hasKey("jewel"))
+ {
+ NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel");
+ ItemStack jewel = new ItemStack(0, 0, 0);
+ jewel.readFromNBT(jewelNBT);
+ if(jewel.itemID == Item.enderPearl.itemID && !stack.getTagCompound().hasKey("x") && !stack.getTagCompound().hasKey("y") && !stack.getTagCompound().hasKey("z"))
+ JewelryNBT.addCoordonates(stack, player.posX, player.posY, player.posZ);
+ }
}
- NBTTagCompound potionNBT = new NBTTagCompound();
- potionNBT.setInteger("potion", potion);
- itemStackData.setTag("potion", potionNBT);
+ return stack;
}
/**
@@ -124,20 +177,43 @@ public class ItemRing extends ItemBase
{
if (stack.hasTagCompound())
{
- if (stack.getTagCompound().hasKey("ingot"))
+ if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("ingot"))
{
NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot");
ItemStack ingotStack = new ItemStack(0, 0, 0);
ingotStack.readFromNBT(ingotNBT);
- list.add(EnumChatFormatting.GRAY + ingotStack.getDisplayName());
+ if(ingotStack != null && ingotStack != new ItemStack(0, 0, 0) && ingotStack.getDisplayName() != null)
+ list.add("Ingot: " + EnumChatFormatting.YELLOW + ingotStack.getDisplayName());
+ }
+
+ if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("jewel"))
+ {
+ NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel");
+ ItemStack jewel = new ItemStack(0, 0, 0);
+ jewel.readFromNBT(jewelNBT);
+ if(jewel != null && jewel != new ItemStack(0, 0, 0) && jewel.getDisplayName() != null)
+ list.add("Jewel: " + EnumChatFormatting.BLUE + jewel.getDisplayName());
}
- if (stack.getTagCompound().hasKey("potion"))
+ if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("modifier"))
{
- NBTTagCompound potionNBT = (NBTTagCompound) stack.getTagCompound().getTag("potion");
- int potion = 0;
- potion = potionNBT.getInteger("potion");
- list.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal(new PotionEffect(potion, 4).getEffectName()));
+ NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier");
+ ItemStack modifier = new ItemStack(0, 0, 0);
+ modifier.readFromNBT(modifierNBT);
+ if(modifier != null && modifier != new ItemStack(0, 0, 0) && modifier.getDisplayName() != null)
+ list.add("Modifier: " + EnumChatFormatting.DARK_PURPLE + modifier.getDisplayName());
+ }
+
+ if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("x") && stack.getTagCompound().hasKey("y") && stack.getTagCompound().hasKey("z"))
+ {
+ NBTTagCompound x = (NBTTagCompound) stack.getTagCompound().getTag("x");
+ NBTTagCompound y = (NBTTagCompound) stack.getTagCompound().getTag("y");
+ NBTTagCompound z = (NBTTagCompound) stack.getTagCompound().getTag("z");
+ double posX = 0, posY = 0, posZ = 0;
+ posX = x.getDouble("x");
+ posY = y.getDouble("y");
+ posZ = z.getDouble("z");
+ list.add(EnumChatFormatting.YELLOW + "X: " + EnumChatFormatting.GRAY + (int)posX + EnumChatFormatting.YELLOW + " Y: " + EnumChatFormatting.GRAY + (int)posY + EnumChatFormatting.YELLOW + " Z: " + EnumChatFormatting.GRAY + (int)posZ);
}
}
}
@@ -145,17 +221,31 @@ public class ItemRing extends ItemBase
@Override
public void onUpdate(ItemStack stack, World par2World, Entity par3Entity, int par4, boolean par5)
{
+ amplifier = 0;
if (stack.hasTagCompound())
{
- if(stack.getTagCompound().hasKey("potion"))
+ if(stack.getTagCompound().hasKey("jewel"))
+ {
+ NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel");
+ ItemStack jewel = new ItemStack(0, 0, 0);
+ jewel.readFromNBT(jewelNBT);
+ if(jewel.itemID == Item.diamond.itemID) amplifier = 1;
+ if(jewel.itemID == Item.emerald.itemID) amplifier = 2;
+ }
+ if(stack.getTagCompound().hasKey("modifier"))
{
if (par3Entity instanceof EntityPlayer)
{
EntityPlayer entityplayer = (EntityPlayer)par3Entity;
- NBTTagCompound potionNBT = (NBTTagCompound) stack.getTagCompound().getTag("potion");
- int potion = 0;
- potion = potionNBT.getInteger("potion");
- if(potion != 0 && entityplayer != null) entityplayer.addPotionEffect(new PotionEffect(potion, 4));
+ NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier");
+ ItemStack modifier = new ItemStack(0, 0, 0);
+ modifier.readFromNBT(modifierNBT);
+ if(modifier.itemID == Item.blazePowder.itemID && entityplayer != null)
+ entityplayer.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 4, amplifier));
+ if(modifier.itemID == Item.sugar.itemID && entityplayer != null)
+ entityplayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 4, amplifier));
+ if(modifier.itemID == Item.pickaxeIron.itemID && entityplayer != null)
+ entityplayer.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 4, amplifier));
}
}
}