diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-06-09 02:15:30 +0100 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-06-09 02:15:30 +0100 |
| commit | 8889b2af5ad007e508adf893e2e0f7ed65e93239 (patch) | |
| tree | 17ef0cfaf08b142997cb752cc0fb4f2d121b935a /src/main | |
| parent | 06e3ea1972f4d1662033f08cb9ff4091b3f44ef1 (diff) | |
Fixed a bug causing servers to crash? (I think)
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java | 279 | ||||
| -rw-r--r-- | src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java | 467 |
2 files changed, 374 insertions, 372 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java index 09054db..1ffdeb7 100644 --- a/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java +++ b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java @@ -1,139 +1,140 @@ -package darkknight.jewelrycraft.item; - -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import javax.imageio.ImageIO; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.client.resources.IResourceManager; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import darkknight.jewelrycraft.util.JewelryNBT; -import darkknight.jewelrycraft.util.Variables; - -public class ItemMoltenMetal extends Item -{ - /** - * - */ - public ItemMoltenMetal() - { - super(); - setMaxStackSize(1); - } - - /** - * @param iconRegister - */ - @Override - public void registerIcons(IIconRegister iconRegister) - { - itemIcon = iconRegister.registerIcon(Variables.MODID + ":moltenMetalStill"); - } - - /** - * @param stack - * @param pass - * @return - */ - @Override - @SideOnly (Side.CLIENT) - public int getColorFromItemStack(ItemStack stack, int pass) - { - try{ - return color(stack, pass); - } - catch(IOException e){ - e.printStackTrace(); - } - return 16777215; - } - - /** - * @param stack - * @param pass - * @return - * @throws IOException - */ - public static int color(ItemStack stack, int pass) throws IOException - { - IResourceManager rm = Minecraft.getMinecraft().getResourceManager(); - ResourceLocation ingot; - BufferedImage icon; - if (stack != null && JewelryNBT.ingot(stack) != null && Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) > 0 && JewelryNBT.ingot(stack).getIconIndex() != null && JewelryNBT.ingotColor(stack) == 16777215){ - try{ - ingot = ItemBaseJewelry.getLocation(JewelryNBT.ingot(stack), stack, false); - } - catch(Exception e){ - ingot = new ResourceLocation("textures/items/apple.png"); - } - icon = ImageIO.read(rm.getResource(ingot).getInputStream()); - int height = icon.getHeight(); - int width = icon.getWidth(); - Map m = new HashMap(); - for(int i = 0; i < width; i++) - for(int j = 0; j < height; j++){ - int rgb = icon.getRGB(i, j); - int red = rgb >> 16 & 0xff; - int green = rgb >> 8 & 0xff; - int blue = rgb & 0xff; - int[] rgbArr = {red, green, blue}; - int Cmax = Math.max(red, Math.max(green, blue)); - int Cmin = Math.min(red, Math.min(green, blue)); - if (!isGray(rgbArr)) m.put(rgb, (Cmax + Cmin) / 2); - } - try{ - int color = getMostCommonColour(m); - if (JewelryNBT.ingot(stack) != null && JewelryNBT.ingot(stack).getItem().getColorFromItemStack(JewelryNBT.ingot(stack), 1) != 16777215) JewelryNBT.addIngotColor(stack, JewelryNBT.ingot(stack).getItem().getColorFromItemStack(JewelryNBT.ingot(stack), 1)); - else JewelryNBT.addIngotColor(stack, color); - } - catch(Exception e){ - JewelryNBT.addIngotColor(stack, 16777215); - } - } - if (JewelryNBT.ingot(stack) != null) return JewelryNBT.ingotColor(stack); - return 0; - } - - /** - * @param map - * @return - */ - public static int getMostCommonColour(Map map) - { - List list = new LinkedList(map.entrySet()); - Collections.sort(list, new Comparator(){ - public int compare(Object o1, Object o2) - { - return ((Comparable)((Map.Entry)o1).getValue()).compareTo(((Map.Entry)o2).getValue()); - } - }); - Map.Entry me = (Map.Entry)list.get(list.size() - 1); - for(int i = 0; i < list.size(); i++){ - float alpha = Float.valueOf(list.get(i).toString().split("=")[1]); - if (alpha < 180) me = (Map.Entry)list.get(i); - } - int rgb = (Integer)me.getKey(); - return rgb; - } - - /** - * @param rgbArr - * @return - */ - public static boolean isGray(int[] rgbArr) - { - int rgbSum = rgbArr[0] + rgbArr[1] + rgbArr[2]; - if (rgbSum > 0 && rgbSum < 256 * 3) return false; - return true; - } -} +package darkknight.jewelrycraft.item;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import javax.imageio.ImageIO;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.client.resources.IResourceManager;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ResourceLocation;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import darkknight.jewelrycraft.util.JewelryNBT;
+import darkknight.jewelrycraft.util.Variables;
+
+public class ItemMoltenMetal extends Item
+{
+ /**
+ *
+ */
+ public ItemMoltenMetal()
+ {
+ super();
+ setMaxStackSize(1);
+ }
+
+ /**
+ * @param iconRegister
+ */
+ @Override
+ public void registerIcons(IIconRegister iconRegister)
+ {
+ itemIcon = iconRegister.registerIcon(Variables.MODID + ":moltenMetalStill");
+ }
+
+ /**
+ * @param stack
+ * @param pass
+ * @return
+ */
+ @Override
+ @SideOnly (Side.CLIENT)
+ public int getColorFromItemStack(ItemStack stack, int pass)
+ {
+ try{
+ return color(stack, pass);
+ }
+ catch(IOException e){
+ e.printStackTrace();
+ }
+ return 16777215;
+ }
+
+ /**
+ * @param stack
+ * @param pass
+ * @return
+ * @throws IOException
+ */
+ @SideOnly(Side.CLIENT)
+ public static int color(ItemStack stack, int pass) throws IOException
+ {
+ IResourceManager rm = Minecraft.getMinecraft().getResourceManager();
+ ResourceLocation ingot;
+ BufferedImage icon;
+ if (stack != null && JewelryNBT.ingot(stack) != null && Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) > 0 && JewelryNBT.ingot(stack).getIconIndex() != null && JewelryNBT.ingotColor(stack) == 16777215){
+ try{
+ ingot = ItemBaseJewelry.getLocation(JewelryNBT.ingot(stack), stack, false);
+ }
+ catch(Exception e){
+ ingot = new ResourceLocation("textures/items/apple.png");
+ }
+ icon = ImageIO.read(rm.getResource(ingot).getInputStream());
+ int height = icon.getHeight();
+ int width = icon.getWidth();
+ Map m = new HashMap();
+ for(int i = 0; i < width; i++)
+ for(int j = 0; j < height; j++){
+ int rgb = icon.getRGB(i, j);
+ int red = rgb >> 16 & 0xff;
+ int green = rgb >> 8 & 0xff;
+ int blue = rgb & 0xff;
+ int[] rgbArr = {red, green, blue};
+ int Cmax = Math.max(red, Math.max(green, blue));
+ int Cmin = Math.min(red, Math.min(green, blue));
+ if (!isGray(rgbArr)) m.put(rgb, (Cmax + Cmin) / 2);
+ }
+ try{
+ int color = getMostCommonColour(m);
+ if (JewelryNBT.ingot(stack) != null && JewelryNBT.ingot(stack).getItem().getColorFromItemStack(JewelryNBT.ingot(stack), 1) != 16777215) JewelryNBT.addIngotColor(stack, JewelryNBT.ingot(stack).getItem().getColorFromItemStack(JewelryNBT.ingot(stack), 1));
+ else JewelryNBT.addIngotColor(stack, color);
+ }
+ catch(Exception e){
+ JewelryNBT.addIngotColor(stack, 16777215);
+ }
+ }
+ if (JewelryNBT.ingot(stack) != null) return JewelryNBT.ingotColor(stack);
+ return 0;
+ }
+
+ /**
+ * @param map
+ * @return
+ */
+ public static int getMostCommonColour(Map map)
+ {
+ List list = new LinkedList(map.entrySet());
+ Collections.sort(list, new Comparator(){
+ public int compare(Object o1, Object o2)
+ {
+ return ((Comparable)((Map.Entry)o1).getValue()).compareTo(((Map.Entry)o2).getValue());
+ }
+ });
+ Map.Entry me = (Map.Entry)list.get(list.size() - 1);
+ for(int i = 0; i < list.size(); i++){
+ float alpha = Float.valueOf(list.get(i).toString().split("=")[1]);
+ if (alpha < 180) me = (Map.Entry)list.get(i);
+ }
+ int rgb = (Integer)me.getKey();
+ return rgb;
+ }
+
+ /**
+ * @param rgbArr
+ * @return
+ */
+ public static boolean isGray(int[] rgbArr)
+ {
+ int rgbSum = rgbArr[0] + rgbArr[1] + rgbArr[2];
+ if (rgbSum > 0 && rgbSum < 256 * 3) return false;
+ return true;
+ }
+}
diff --git a/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java index c7d32b4..1cacc37 100644 --- a/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java +++ b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java @@ -1,233 +1,234 @@ -package darkknight.jewelrycraft.item; - -import java.io.IOException; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IIconRegister; -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.util.IIcon; -import net.minecraft.util.MovingObjectPosition; -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.network.PacketSendLiquidData; -import darkknight.jewelrycraft.util.JewelryNBT; -import darkknight.jewelrycraft.util.Variables; - -public class ItemMoltenMetalBucket extends Item -{ - public IIcon liquid; - - /** - * - */ - public ItemMoltenMetalBucket() - { - maxStackSize = 1; - } - - /** - * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer - * - * @param stack - * @param par2World - * @param par3EntityPlayer - * @return - */ - @Override - public ItemStack onItemRightClick(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer) - { - boolean flag = BlockList.moltenMetal == Blocks.air; - MovingObjectPosition movingobjectposition = 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; - par2World.getBlock(i, j, k).getMaterial(); - par2World.getBlockMetadata(i, j, k); - par2World.setBlockToAir(i, j, k); - return 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 (tryPlaceContainedLiquid(par2World, i, j, k, stack) && !par3EntityPlayer.capabilities.isCreativeMode) return new ItemStack(Items.bucket); - } - catch(IOException e){ - e.printStackTrace(); - } - } - } - return stack; - } - } - - /** - * @param p_150910_1_ - * @param p_150910_2_ - * @param p_150910_3_ - * @return - */ - 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. - * - * @param world - * @param x - * @param y - * @param z - * @param stack - * @return - * @throws IOException - */ - public boolean tryPlaceContainedLiquid(World world, int x, int y, int z, ItemStack stack) throws IOException - { - if (BlockList.moltenMetal == Blocks.air) return false; - else{ - Material material = world.getBlock(x, y, z).getMaterial(); - boolean flag = !material.isSolid(); - if (!world.isAirBlock(x, y, z) && !flag) return false; - else if (stack != null && JewelryNBT.ingot(stack) != null){ - if (!world.isRemote && flag && !material.isLiquid()) world.func_147480_a(x, y, z, true); - int color = color(stack, 1); - JewelrycraftMod.saveData.setString(x + " " + y + " " + z + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage() + ":" + color); - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage(), color)); - world.setBlock(x, y, z, BlockList.moltenMetal, 0, 3); - return true; - }else return false; - } - } - - /** - * @param iconRegister - */ - @Override - public void registerIcons(IIconRegister iconRegister) - { - itemIcon = iconRegister.registerIcon("bucket_empty"); - liquid = iconRegister.registerIcon(Variables.MODID + ":bucketOverlay"); - } - - /** - * @param stack - * @param pass - * @return - */ - @Override - @SideOnly (Side.CLIENT) - public int getColorFromItemStack(ItemStack stack, int pass) - { - try{ - return color(stack, pass); - } - catch(IOException e){ - e.printStackTrace(); - } - return 16777215; - } - - /** - * @return - */ - @Override - public boolean requiresMultipleRenderPasses() - { - return true; - } - - /** - * @param stack - * @param pass - * @return - */ - @Override - public IIcon getIcon(ItemStack stack, int pass) - { - if (pass == 0) return itemIcon; - if (pass == 1) return liquid; - return itemIcon; - } - - /** - * @param stack - * @param pass - * @return - * @throws IOException - */ - public static int color(ItemStack stack, int pass) throws IOException - { - if (pass == 1) return ItemMoltenMetal.color(stack, pass); - return 16777215; - } - - /** - * @param ingot - * @return - */ - public ItemStack getModifiedItemStack(ItemStack ingot) - { - ItemStack itemstack = new ItemStack(this); - JewelryNBT.addMetal(itemstack, ingot); - return itemstack; - } - - /** - * @param stack - * @return - */ - @Override - public String getItemStackDisplayName(ItemStack stack) - { - try{ - if (JewelryNBT.ingot(stack) != null){ - ItemStack ingot = JewelryNBT.ingot(stack); - if (ingot != null){ - if (Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.carpet)) ingot.setItemDamage(15 - ingot.getItemDamage()); - return StatCollector.translateToLocal(getUnlocalizedNameInefficiently(stack) + ".name").trim() + " " + ingot.getDisplayName().replace("Ingot", " ").trim(); - }else return StatCollector.translateToLocal("bucket.unknown"); - } - } - catch(Exception e){ - System.out.println("Error: " + e); - } - return ("" + StatCollector.translateToLocal(getUnlocalizedNameInefficiently(stack) + ".name")).trim() + " " + StatCollector.translateToLocal("info.jewelrycraft2.metal"); - } -} +package darkknight.jewelrycraft.item;
+
+import java.io.IOException;
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+import net.minecraft.client.renderer.texture.IIconRegister;
+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.util.IIcon;
+import net.minecraft.util.MovingObjectPosition;
+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.network.PacketSendLiquidData;
+import darkknight.jewelrycraft.util.JewelryNBT;
+import darkknight.jewelrycraft.util.Variables;
+
+public class ItemMoltenMetalBucket extends Item
+{
+ public IIcon liquid;
+
+ /**
+ *
+ */
+ public ItemMoltenMetalBucket()
+ {
+ maxStackSize = 1;
+ }
+
+ /**
+ * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
+ *
+ * @param stack
+ * @param par2World
+ * @param par3EntityPlayer
+ * @return
+ */
+ @Override
+ public ItemStack onItemRightClick(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer)
+ {
+ boolean flag = BlockList.moltenMetal == Blocks.air;
+ MovingObjectPosition movingobjectposition = 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;
+ par2World.getBlock(i, j, k).getMaterial();
+ par2World.getBlockMetadata(i, j, k);
+ par2World.setBlockToAir(i, j, k);
+ return 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 (tryPlaceContainedLiquid(par2World, i, j, k, stack) && !par3EntityPlayer.capabilities.isCreativeMode) return new ItemStack(Items.bucket);
+ }
+ catch(IOException e){
+ e.printStackTrace();
+ }
+ }
+ }
+ return stack;
+ }
+ }
+
+ /**
+ * @param p_150910_1_
+ * @param p_150910_2_
+ * @param p_150910_3_
+ * @return
+ */
+ 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.
+ *
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @param stack
+ * @return
+ * @throws IOException
+ */
+ public boolean tryPlaceContainedLiquid(World world, int x, int y, int z, ItemStack stack) throws IOException
+ {
+ if (BlockList.moltenMetal == Blocks.air) return false;
+ else{
+ Material material = world.getBlock(x, y, z).getMaterial();
+ boolean flag = !material.isSolid();
+ if (!world.isAirBlock(x, y, z) && !flag) return false;
+ else if (stack != null && JewelryNBT.ingot(stack) != null){
+ if (!world.isRemote && flag && !material.isLiquid()) world.func_147480_a(x, y, z, true);
+ int color = color(stack, 1);
+ JewelrycraftMod.saveData.setString(x + " " + y + " " + z + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage() + ":" + color);
+ JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage(), color));
+ world.setBlock(x, y, z, BlockList.moltenMetal, 0, 3);
+ return true;
+ }else return false;
+ }
+ }
+
+ /**
+ * @param iconRegister
+ */
+ @Override
+ public void registerIcons(IIconRegister iconRegister)
+ {
+ itemIcon = iconRegister.registerIcon("bucket_empty");
+ liquid = iconRegister.registerIcon(Variables.MODID + ":bucketOverlay");
+ }
+
+ /**
+ * @param stack
+ * @param pass
+ * @return
+ */
+ @Override
+ @SideOnly (Side.CLIENT)
+ public int getColorFromItemStack(ItemStack stack, int pass)
+ {
+ try{
+ return color(stack, pass);
+ }
+ catch(IOException e){
+ e.printStackTrace();
+ }
+ return 16777215;
+ }
+
+ /**
+ * @return
+ */
+ @Override
+ public boolean requiresMultipleRenderPasses()
+ {
+ return true;
+ }
+
+ /**
+ * @param stack
+ * @param pass
+ * @return
+ */
+ @Override
+ public IIcon getIcon(ItemStack stack, int pass)
+ {
+ if (pass == 0) return itemIcon;
+ if (pass == 1) return liquid;
+ return itemIcon;
+ }
+
+ /**
+ * @param stack
+ * @param pass
+ * @return
+ * @throws IOException
+ */
+ @SideOnly(Side.CLIENT)
+ public static int color(ItemStack stack, int pass) throws IOException
+ {
+ if (pass == 1) return ItemMoltenMetal.color(stack, pass);
+ return 16777215;
+ }
+
+ /**
+ * @param ingot
+ * @return
+ */
+ public ItemStack getModifiedItemStack(ItemStack ingot)
+ {
+ ItemStack itemstack = new ItemStack(this);
+ JewelryNBT.addMetal(itemstack, ingot);
+ return itemstack;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ @Override
+ public String getItemStackDisplayName(ItemStack stack)
+ {
+ try{
+ if (JewelryNBT.ingot(stack) != null){
+ ItemStack ingot = JewelryNBT.ingot(stack);
+ if (ingot != null){
+ if (Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.carpet)) ingot.setItemDamage(15 - ingot.getItemDamage());
+ return StatCollector.translateToLocal(getUnlocalizedNameInefficiently(stack) + ".name").trim() + " " + ingot.getDisplayName().replace("Ingot", " ").trim();
+ }else return StatCollector.translateToLocal("bucket.unknown");
+ }
+ }
+ catch(Exception e){
+ System.out.println("Error: " + e);
+ }
+ return ("" + StatCollector.translateToLocal(getUnlocalizedNameInefficiently(stack) + ".name")).trim() + " " + StatCollector.translateToLocal("info.jewelrycraft2.metal");
+ }
+}
|
