From d8bcaa05a5536f76aaf3d2286d3bb1c368586d1e Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Wed, 18 Dec 2013 23:54:49 +0200 Subject: Added clay molds, fixed particles issues, rings now take the color of the ingot used. --- .../jewelrycraft/item/ItemClayMolds.java | 72 ++++++++++++++++++++++ common/darkknight/jewelrycraft/item/ItemList.java | 2 + common/darkknight/jewelrycraft/item/ItemRing.java | 53 +++++++++++++++- 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 common/darkknight/jewelrycraft/item/ItemClayMolds.java (limited to 'common/darkknight/jewelrycraft/item') diff --git a/common/darkknight/jewelrycraft/item/ItemClayMolds.java b/common/darkknight/jewelrycraft/item/ItemClayMolds.java new file mode 100644 index 0000000..184db0d --- /dev/null +++ b/common/darkknight/jewelrycraft/item/ItemClayMolds.java @@ -0,0 +1,72 @@ +package darkknight.jewelrycraft.item; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.List; + +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Icon; +import net.minecraft.util.MathHelper; + +public class ItemClayMolds extends Item +{ + /** List of molds color names */ + public static final String[] moldsItemNames = new String[] { "clayIngot", "clayRing" }; + @SideOnly(Side.CLIENT) + private Icon[] moldsIcons; + + public ItemClayMolds(int par1) + { + super(par1); + this.setHasSubtypes(true); + this.setMaxDamage(0); + this.setMaxStackSize(1); + } + + @SideOnly(Side.CLIENT) + /** + * Gets an icon index based on an item's damage value + */ + public Icon getIconFromDamage(int par1) + { + int j = MathHelper.clamp_int(par1, 0, moldsItemNames.length - 1); + return this.moldsIcons[j]; + } + + /** + * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have different names based on + * their damage or NBT. + */ + public String getUnlocalizedName(ItemStack par1ItemStack) + { + int i = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, moldsItemNames.length - 1); + return super.getUnlocalizedName() + "." + moldsItemNames[i]; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @SideOnly(Side.CLIENT) + /** + * returns a list of items with the same ID, but different meta (eg: molds returns 16 items) + */ + public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) + { + for (int j = 0; j < moldsItemNames.length; ++j) + { + par3List.add(new ItemStack(par1, 1, j)); + } + } + + @SideOnly(Side.CLIENT) + public void registerIcons(IconRegister par1IconRegister) + { + this.moldsIcons = new Icon[moldsItemNames.length]; + + for (int i = 0; i < moldsItemNames.length; ++i) + { + this.moldsIcons[i] = par1IconRegister.registerIcon("jewelrycraft:" + moldsItemNames[i] + this.getIconString()); + } + } +} diff --git a/common/darkknight/jewelrycraft/item/ItemList.java b/common/darkknight/jewelrycraft/item/ItemList.java index 3309faf..3810d6a 100644 --- a/common/darkknight/jewelrycraft/item/ItemList.java +++ b/common/darkknight/jewelrycraft/item/ItemList.java @@ -10,6 +10,7 @@ public class ItemList public static Item thiefGloves; public static Item shadowIngot; public static Item molds; + public static Item clayMolds; public static Item ring; private static boolean isInitialized = false; @@ -21,6 +22,7 @@ public class ItemList thiefGloves = new ItemThiefGloves(ConfigHandler.idThiefGloves).setUnlocalizedName("jewelrycraft.thiefGloves").setCreativeTab(JewelrycraftMod.jewelrycraft); shadowIngot = new ItemBase(ConfigHandler.idShadowIngot).setUnlocalizedName("jewelrycraft.ingotShadow").setCreativeTab(JewelrycraftMod.jewelrycraft); molds = new ItemMolds(ConfigHandler.idMolds).setUnlocalizedName("jewelrycraft.mold").setTextureName("Mold").setCreativeTab(JewelrycraftMod.jewelrycraft); + clayMolds = new ItemClayMolds(ConfigHandler.idClayMolds).setUnlocalizedName("jewelrycraft.mold").setTextureName("Mold").setCreativeTab(JewelrycraftMod.jewelrycraft); ring = new ItemRing(ConfigHandler.idRing).setUnlocalizedName("jewelrycraft.ring").setCreativeTab(JewelrycraftMod.jewelrycraft); isInitialized = true; diff --git a/common/darkknight/jewelrycraft/item/ItemRing.java b/common/darkknight/jewelrycraft/item/ItemRing.java index ea75aa2..3941770 100644 --- a/common/darkknight/jewelrycraft/item/ItemRing.java +++ b/common/darkknight/jewelrycraft/item/ItemRing.java @@ -1,13 +1,23 @@ package darkknight.jewelrycraft.item; +import java.awt.image.BufferedImage; +import java.io.IOException; import java.util.List; +import javax.imageio.ImageIO; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.ResourceManager; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.PotionEffect; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; public class ItemRing extends ItemBase @@ -18,6 +28,47 @@ public class ItemRing extends ItemBase this.setMaxStackSize(1); } + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(ItemStack par1ItemStack, int par2) + { + try + { + return color(par1ItemStack); + } + catch (IOException e) + { + e.printStackTrace(); + } + return 0; + } + + public int color(ItemStack stack) throws IOException + { + if (stack.hasTagCompound()) + { + 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() != "") + { + 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); + } + } + } + return 0; + } + public static void addMetal(ItemStack item, ItemStack metal) { NBTTagCompound itemStackData; @@ -51,7 +102,7 @@ public class ItemRing extends ItemBase * allows items to add custom lines of information to the mouseover description */ @Override - @SuppressWarnings({ "rawtypes", "unchecked", "static-access" }) + @SuppressWarnings({ "rawtypes", "unchecked"}) public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { if (stack.hasTagCompound()) -- cgit v1.2.3