diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-04-15 22:41:43 +0300 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-04-15 22:41:43 +0300 |
| commit | 4b8b13b34d7a8fd0ee7c7b13f11be9c2bf3b5d18 (patch) | |
| tree | b49bc483d576ec3abeb2e18523e4511ecce353d3 /eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item | |
| parent | 86398ed60db321f86e8d98f191107fdac2c93760 (diff) | |
More 1.7 stuff
Diffstat (limited to 'eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item')
4 files changed, 358 insertions, 58 deletions
diff --git a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemList.java b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemList.java index 3ac524d..3a91c7b 100644 --- a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemList.java +++ b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemList.java @@ -1,47 +1,55 @@ package darkknight.jewelrycraft.item; +import net.minecraft.init.Items; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; import darkknight.jewelrycraft.JewelrycraftMod; -import darkknight.jewelrycraft.config.ConfigHandler; +import darkknight.jewelrycraft.block.BlockList; public class ItemList { - public static Item thiefGloves; - public static Item shadowIngot; - public static Item molds; - public static Item clayMolds; - public static Item crystal; - public static ItemRing ring; - public static ItemNecklace necklace; - public static Item guide; + public static Item thiefGloves; + public static Item shadowIngot; + public static Item molds; + public static Item clayMolds; + public static Item crystal; + public static ItemRing ring; + public static ItemNecklace necklace; + public static Item guide; + public static ItemMoltenMetalBucket bucket; - private static boolean isInitialized = false; + private static boolean isInitialized = false; - public static void preInit(FMLPreInitializationEvent e) - { - if (!isInitialized) - { - thiefGloves = new ItemThiefGloves().setUnlocalizedName("Jewelrycraft.thiefGloves").setTextureName("jewelrycraft:thiefGloves").setCreativeTab(JewelrycraftMod.jewelrycraft); - shadowIngot = new Item().setUnlocalizedName("Jewelrycraft.ingotShadow").setTextureName("jewelrycraft:ingotShadow").setCreativeTab(JewelrycraftMod.jewelrycraft); - molds = new ItemMolds().setUnlocalizedName("Jewelrycraft.mold").setTextureName("Mold").setCreativeTab(JewelrycraftMod.jewelrycraft); - clayMolds = new ItemClayMolds().setUnlocalizedName("Jewelrycraft.mold").setTextureName("Mold").setCreativeTab(JewelrycraftMod.jewelrycraft); - ring = (ItemRing) new ItemRing().setUnlocalizedName("Jewelrycraft.ring").setTextureName("jewelrycraft:ring"); - crystal = new ItemCrystal().setUnlocalizedName("Jewelrycraft.crystal").setTextureName("jewelrycraft:crystal").setCreativeTab(JewelrycraftMod.jewelrycraft); - necklace = (ItemNecklace) new ItemNecklace().setUnlocalizedName("Jewelrycraft.necklace").setTextureName("jewelrycraft:necklace"); - guide = new ItemGuide().setUnlocalizedName("Jewelrycraft.guide").setTextureName("jewelrycraft:guide").setCreativeTab(JewelrycraftMod.jewelrycraft); + public static void preInit(FMLPreInitializationEvent e) + { + if (!isInitialized) + { + thiefGloves = new ItemThiefGloves().setUnlocalizedName("Jewelrycraft.thiefGloves").setTextureName("jewelrycraft:thiefGloves").setCreativeTab(JewelrycraftMod.jewelrycraft); + shadowIngot = new Item().setUnlocalizedName("Jewelrycraft.ingotShadow").setTextureName("jewelrycraft:ingotShadow").setCreativeTab(JewelrycraftMod.jewelrycraft); + molds = new ItemMolds().setUnlocalizedName("Jewelrycraft.mold").setTextureName("Mold").setCreativeTab(JewelrycraftMod.jewelrycraft); + clayMolds = new ItemClayMolds().setUnlocalizedName("Jewelrycraft.mold").setTextureName("Mold").setCreativeTab(JewelrycraftMod.jewelrycraft); + ring = (ItemRing) new ItemRing().setUnlocalizedName("Jewelrycraft.ring").setTextureName("jewelrycraft:ring"); + crystal = new ItemCrystal().setUnlocalizedName("Jewelrycraft.crystal").setTextureName("jewelrycraft:crystal").setCreativeTab(JewelrycraftMod.jewelrycraft); + necklace = (ItemNecklace) new ItemNecklace().setUnlocalizedName("Jewelrycraft.necklace").setTextureName("jewelrycraft:necklace"); + guide = new ItemGuide().setUnlocalizedName("Jewelrycraft.guide").setTextureName("jewelrycraft:guide").setCreativeTab(JewelrycraftMod.jewelrycraft); + bucket = (ItemMoltenMetalBucket) new ItemMoltenMetalBucket().setUnlocalizedName("Jewelrycraft.bucket"); - GameRegistry.registerItem(thiefGloves, "thiefGloves"); - GameRegistry.registerItem(shadowIngot, "shadowIngot"); - GameRegistry.registerItem(molds, "molds"); - GameRegistry.registerItem(clayMolds, "clayMolds"); - GameRegistry.registerItem(ring, "ring"); - GameRegistry.registerItem(necklace, "necklace"); - GameRegistry.registerItem(crystal, "crystal"); - GameRegistry.registerItem(guide, "guide"); + GameRegistry.registerItem(thiefGloves, "thiefGloves"); + GameRegistry.registerItem(shadowIngot, "shadowIngot"); + GameRegistry.registerItem(molds, "molds"); + GameRegistry.registerItem(clayMolds, "clayMolds"); + GameRegistry.registerItem(ring, "ring"); + GameRegistry.registerItem(necklace, "necklace"); + GameRegistry.registerItem(crystal, "crystal"); + GameRegistry.registerItem(guide, "guide"); + GameRegistry.registerItem(bucket, "moltenMetalBucket"); - isInitialized = true; - } - } + isInitialized = true; + } + } } diff --git a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java new file mode 100644 index 0000000..18a17ad --- /dev/null +++ b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java @@ -0,0 +1,309 @@ +package darkknight.jewelrycraft.item; + +import java.awt.image.BufferedImage; +import java.io.BufferedOutputStream; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; + +import javax.imageio.ImageIO; + +import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.FillBucketEvent; +import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.block.BlockList; +import darkknight.jewelrycraft.util.JewelryNBT; +import darkknight.jewelrycraft.util.JewelrycraftUtil; + +public class ItemMoltenMetalBucket extends Item +{ + public IIcon liquid; + public ItemMoltenMetalBucket() + { + this.maxStackSize = 1; + } + + /** + * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer + */ + public ItemStack onItemRightClick(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer) + { + boolean flag = BlockList.moltenMetal == Blocks.air; + MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, flag); + + if (movingobjectposition == null) + { + return stack; + } + else + { + FillBucketEvent event = new FillBucketEvent(par3EntityPlayer, stack, par2World, movingobjectposition); + if (MinecraftForge.EVENT_BUS.post(event)) + { + return stack; + } + + if (event.getResult() == Event.Result.ALLOW) + { + if (par3EntityPlayer.capabilities.isCreativeMode) + { + return stack; + } + + if (--stack.stackSize <= 0) + { + return event.result; + } + + if (!par3EntityPlayer.inventory.addItemStackToInventory(event.result)) + { + par3EntityPlayer.dropPlayerItemWithRandomChoice(event.result, false); + } + + return stack; + } + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) + { + int i = movingobjectposition.blockX; + int j = movingobjectposition.blockY; + int k = movingobjectposition.blockZ; + + if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) + { + return stack; + } + + if (flag) + { + if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, stack)) + { + return stack; + } + + Material material = par2World.getBlock(i, j, k).getMaterial(); + int l = par2World.getBlockMetadata(i, j, k); + par2World.setBlockToAir(i, j, k); + return this.func_150910_a(stack, par3EntityPlayer, ItemList.bucket); + } + else + { + if (BlockList.moltenMetal == Blocks.air) + { + return new ItemStack(Items.bucket); + } + + if (movingobjectposition.sideHit == 0) + { + --j; + } + + if (movingobjectposition.sideHit == 1) + { + ++j; + } + + if (movingobjectposition.sideHit == 2) + { + --k; + } + + if (movingobjectposition.sideHit == 3) + { + ++k; + } + + if (movingobjectposition.sideHit == 4) + { + --i; + } + + if (movingobjectposition.sideHit == 5) + { + ++i; + } + + if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, stack)) + { + return stack; + } + + try { + if (this.tryPlaceContainedLiquid(par2World, i, j, k, stack) && !par3EntityPlayer.capabilities.isCreativeMode) + { + return new ItemStack(Items.bucket); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + return stack; + } + } + + private ItemStack func_150910_a(ItemStack p_150910_1_, EntityPlayer p_150910_2_, Item p_150910_3_) + { + if (p_150910_2_.capabilities.isCreativeMode) + { + return p_150910_1_; + } + else if (--p_150910_1_.stackSize <= 0) + { + return new ItemStack(p_150910_3_); + } + else + { + if (!p_150910_2_.inventory.addItemStackToInventory(new ItemStack(p_150910_3_))) + { + p_150910_2_.dropPlayerItemWithRandomChoice(new ItemStack(p_150910_3_, 1, 0), false); + } + + return p_150910_1_; + } + } + + /** + * Attempts to place the liquid contained inside the bucket. + * @throws IOException + */ + public boolean tryPlaceContainedLiquid(World par1World, int par2, int par3, int par4, ItemStack stack) throws IOException + { + if (BlockList.moltenMetal == Blocks.air) + { + return false; + } + else + { + Material material = par1World.getBlock(par2, par3, par4).getMaterial(); + boolean flag = !material.isSolid(); + + if (!par1World.isAirBlock(par2, par3, par4) && !flag) return false; + else + { + if (!par1World.isRemote && flag && !material.isLiquid()) par1World.func_147480_a(par2, par3, par4, true); + JewelrycraftUtil.liquids.put(String.valueOf(par2) + " " + String.valueOf(par3) + " " + String.valueOf(par4), JewelryNBT.ingot(stack).getItem()); + JewelrycraftMod.saveData = new NBTTagCompound(); + JewelrycraftMod.saveData.setString("coords", String.valueOf(par2) + " " + String.valueOf(par3) + " " + String.valueOf(par4)); + JewelrycraftMod.saveData.setInteger("item", Item.getIdFromItem(JewelryNBT.ingot(stack).getItem())); + CompressedStreamTools.writeCompressed(JewelrycraftMod.saveData, new FileOutputStream(JewelrycraftMod.liquidsConf)); + System.out.println(JewelrycraftMod.saveData.getString("coords")); + par1World.setBlock(par2, par3, par4, BlockList.moltenMetal, 0, 3); + return true; + } + } + } + + public void registerIcons(IIconRegister iconRegister) + { + itemIcon = iconRegister.registerIcon("bucket_empty"); + liquid = iconRegister.registerIcon("jewelrycraft:bucketOverlay"); + } + + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(ItemStack stack, int pass) + { + try + { + return color(stack, pass); + } + catch (IOException e) + { + e.printStackTrace(); + } + return 16777215; + } + + @Override + public boolean requiresMultipleRenderPasses() + { + return true; + } + + public IIcon getIcon(ItemStack stack, int pass) + { + if(pass == 0) return itemIcon; + if(pass == 1) return liquid; + return itemIcon; + } + + public static int color(ItemStack stack, int pass) throws IOException + { + String domain = "", texture; + IResourceManager rm = Minecraft.getMinecraft().getResourceManager(); + BufferedImage icon; + int x=0, y=0, ok = 0, red, green, blue; + if (pass == 1 && JewelryNBT.ingot(stack) != null && JewelryNBT.ingot(stack).getIconIndex() != null && JewelryNBT.ingotColor(stack) == 16777215) + { + String ingotIconName = JewelryNBT.ingot(stack).getIconIndex().getIconName(); + + if (ingotIconName.substring(0, ingotIconName.indexOf(":") + 1) != "") domain = ingotIconName.substring(0, ingotIconName.indexOf(":") + 1).replace(":", " ").trim(); + else domain = "minecraft"; + + texture = ingotIconName.substring(ingotIconName.lastIndexOf(":") + 1) + ".png"; + ResourceLocation ingot = null; + + if (JewelryNBT.ingot(stack).getUnlocalizedName().contains("item")) ingot = new ResourceLocation(domain, "textures/items/" + texture); + else ingot = new ResourceLocation(domain, "textures/blocks/" + texture); + + icon = ImageIO.read(rm.getResource(ingot).getInputStream()); + while(ok == 0) + { + red = (icon.getRGB(x, y) >> 16) & 0xFF; + green = (icon.getRGB(x, y) >> 8) & 0xFF; + blue = icon.getRGB(x, y) & 0xFF; + if((red <= 80 && green <= 80 && blue <= 80) || (red >= 180 && green >= 180 && blue >= 180)) + { + if(x<icon.getTileWidth()-1) x++; + if(x>=icon.getTileWidth()-1 && y<icon.getTileWidth()-1) + { + x=0; + y++; + } + if(x == icon.getTileWidth()-1 && y==icon.getTileWidth()-1) ok=1; + } + else ok=1; + } + JewelryNBT.addIngotColor(stack, icon.getRGB(x, y)); + } + if(JewelryNBT.ingot(stack) != null && pass == 1) return JewelryNBT.ingotColor(stack); + return 16777215; + } + + public ItemStack getModifiedItemStack(ItemStack ingot) + { + ItemStack itemstack = new ItemStack(this); + JewelryNBT.addMetal(itemstack, ingot); + return itemstack; + } + + public String getItemStackDisplayName(ItemStack stack) + { + if(JewelryNBT.ingot(stack) != null) return (StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim() + " " + JewelryNBT.ingot(stack).getDisplayName().replace("Ingot", " ").trim() ; + return ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim() + " Metal"; + } +} diff --git a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemNecklace.java b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemNecklace.java index 4503406..71af0a0 100644 --- a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemNecklace.java +++ b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemNecklace.java @@ -72,7 +72,7 @@ public class ItemNecklace extends Item return itemIcon; } - public String getItemDisplayName(ItemStack stack) + public String getItemStackDisplayName(ItemStack stack) { if(JewelryNBT.ingot(stack) != null) return JewelryNBT.ingot(stack).getDisplayName().replace("Ingot", " ").trim() + " " + ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim(); return ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim(); @@ -215,22 +215,12 @@ public class ItemNecklace extends Item for(int x = (int) - 1; x <= 1; x++) for(int z = (int) - 1; z <= 1; z++) if(JewelryNBT.isModifierX(stack, new ItemStack(Items.diamond_pickaxe)) && JewelryNBT.isJewelX(stack, new ItemStack(Items.nether_star)) && JewelryNBT.isIngotX(stack, new ItemStack(ItemList.shadowIngot))) - if((side == 0 || side == 1) && j > 0 && world.getBlock(i + x, j, k + z) != Blocks.bedrock) destroyBlock(world, i + x, j, k + z); - else if((side == 2 || side == 3) && j + x > 0 && world.getBlock(i + z, j + x, k) != Blocks.bedrock) destroyBlock(world, i + z, j + x, k); - else if((side == 4 || side == 5) && j + x > 0 && world.getBlock(i, j + x, k + z) != Blocks.bedrock) destroyBlock(world, i, j + x, k + z); + if((side == 0 || side == 1) && j > 0 && world.getBlock(i + x, j, k + z) != Blocks.bedrock) world.func_147480_a(i + x, j, k + z, true); + else if((side == 2 || side == 3) && j + x > 0 && world.getBlock(i + z, j + x, k) != Blocks.bedrock) world.func_147480_a(i + z, j + x, k, true); + else if((side == 4 || side == 5) && j + x > 0 && world.getBlock(i, j + x, k + z) != Blocks.bedrock) world.func_147480_a(i, j + x, k + z, true); } return true; } - - public void destroyBlock(World world, int i, int j, int k) - { - EntityItem entityitem = new EntityItem(world, i + 0.5D, j + 1D, k + 0.5D, new ItemStack(world.getBlock(i, j, k))); - entityitem.motionX = 0; - entityitem.motionZ = 0; - entityitem.motionY = 0.21000000298023224D; - world.spawnEntityInWorld(entityitem); - world.setBlockToAir(i, j, k); - } public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) { diff --git a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemRing.java b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemRing.java index 03e4f1a..fff9120 100644 --- a/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemRing.java +++ b/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/item/ItemRing.java @@ -172,7 +172,7 @@ public class ItemRing extends Item return 16777215; } - public String getItemDisplayName(ItemStack stack) + public String getItemStackDisplayName(ItemStack stack) { if (JewelryNBT.ingot(stack) != null && JewelryNBT.jewel(stack) != null && JewelryNBT.modifier(stack) == null && JewelryNBT.isJewelX(stack, new ItemStack(Items.diamond)) && JewelryNBT.isIngotX(stack, new ItemStack(Items.gold_ingot))) return "Wedding Ring"; else if(JewelryNBT.ingot(stack) != null) return JewelryNBT.ingot(stack).getDisplayName().replace("Ingot", " ").trim() + " " + ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim(); @@ -240,7 +240,7 @@ public class ItemRing extends Item } if(JewelryNBT.isModeX(stack, "Activated")) mode = "Deactivated"; else if(JewelryNBT.isModeX(stack, "Deactivated")) mode = "Activated"; - if(mode != "") + if(mode != "" && mode != "Transfer" && mode != "Enchant" && mode != "Disenchant") { player.addChatMessage(new ChatComponentText("The Ring has been " + mode)); JewelryNBT.addMode(stack, mode); @@ -371,14 +371,7 @@ public class ItemRing extends Item } } if(JewelryNBT.isModifierX(stack, new ItemStack(Items.diamond_pickaxe)) && JewelryNBT.isJewelX(stack, new ItemStack(Items.nether_star)) && JewelryNBT.isIngotX(stack, new ItemStack(ItemList.shadowIngot)) && j > 0 && world.getBlock(i, j, k) != Blocks.bedrock) - { - EntityItem entityitem = new EntityItem(world, i + 0.5D, j + 1D, k + 0.5D, new ItemStack(world.getBlock(i, j, k))); - entityitem.motionX = 0; - entityitem.motionZ = 0; - entityitem.motionY = 0.21000000298023224D; - world.spawnEntityInWorld(entityitem); - world.setBlockToAir(i, j, k); - } + world.func_147480_a(i, j, k, true); } return true; } @@ -443,7 +436,7 @@ public class ItemRing extends Item } else if (JewelryNBT.isModifierX(stack, new ItemStack(Items.potionitem, 1, 8270)) && entityplayer != null) entityplayer.addPotionEffect(new PotionEffect(Potion.invisibility.id, 4, amplifier, true)); } - if(entityplayer.inventory.getCurrentItem() != null && JewelryNBT.isJewelX(stack, new ItemStack(Items.nether_star)) && JewelryNBT.isModifierX(stack, new ItemStack(Items.book)) && entityplayer.inventory.getCurrentItem().equals(stack)) + if(entityplayer.inventory.getCurrentItem() != null && JewelryNBT.isJewelX(stack, new ItemStack(Items.nether_star)) && JewelryNBT.isModifierX(stack, new ItemStack(Items.book)) && entityplayer.inventory.getCurrentItem().getItem() == stack.getItem()) { ItemStack item = null; if(entityplayer.inventory.currentItem + 1 <= 8 && entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1) != null && entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1).isItemEnchanted()) item = entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1); |
