From 2f93a3de229a3351d91708cf60fbc9ab7a1be97f Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Thu, 11 Jun 2015 19:59:48 +0100 Subject: Improved color detection system by 10000000%! (not rly, but it's better than b4) --- .../jewelrycraft/block/BlockMoltenMetal.java | 10 +- .../jewelrycraft/block/BlockSmelter.java | 13 +- .../jewelrycraft/events/BucketHandler.java | 155 +++--- .../jewelrycraft/item/ItemMoltenMetal.java | 92 +--- .../jewelrycraft/item/ItemMoltenMetalBucket.java | 20 +- .../network/PacketRequestLiquidData.java | 163 +++--- .../jewelrycraft/network/PacketSendLiquidData.java | 196 ++++---- .../darkknight/jewelrycraft/proxy/ClientProxy.java | 14 +- .../jewelrycraft/util/JewelrycraftUtil.java | 549 ++++++++++++--------- .../jewelrycraft/worldGen/WorldGenStructure2.java | 23 +- .../jewelrycraft/worldGen/WorldGenStructure5.java | 22 +- 11 files changed, 616 insertions(+), 641 deletions(-) (limited to 'src') diff --git a/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java b/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java index fd7c264..2525dd3 100644 --- a/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java +++ b/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java @@ -2,12 +2,14 @@ package darkknight.jewelrycraft.block; import java.io.IOException; import java.util.Random; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.init.Blocks; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -18,6 +20,7 @@ import cpw.mods.fml.relauncher.SideOnly; import darkknight.jewelrycraft.JewelrycraftMod; import darkknight.jewelrycraft.network.PacketRequestLiquidData; import darkknight.jewelrycraft.network.PacketSendLiquidData; +import darkknight.jewelrycraft.util.JewelrycraftUtil; import darkknight.jewelrycraft.util.Variables; public class BlockMoltenMetal extends BlockFluidClassic @@ -218,7 +221,7 @@ public class BlockMoltenMetal extends BlockFluidClassic JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z, world.provider.dimensionId), originData); String[] data = originData.split(":"); try{ - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Integer.parseInt(data[0]), Integer.parseInt(data[1]), Integer.parseInt(data[2]))); + JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Integer.parseInt(data[0]), Integer.parseInt(data[1]))); } catch(Exception e){ System.out.println("The liquids file is either corrupt, missing or the metal for the liquid simply doesn't exist!"); @@ -245,13 +248,12 @@ public class BlockMoltenMetal extends BlockFluidClassic return 0xFFFFFF; }else{ String[] splitData = ingotData.split(":"); - if (splitData.length == 3){ + if (splitData.length == 2){ int color; try{ Integer.parseInt(splitData[0]); Integer.parseInt(splitData[1]); - color = Integer.parseInt(splitData[2]); - return color; + return JewelrycraftUtil.getColor(new ItemStack(Item.getItemById(Integer.parseInt(splitData[0])), 1, Integer.parseInt(splitData[1]))); } catch(Exception e){ e.printStackTrace(); diff --git a/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java b/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java index 4e20a43..1e68e34 100644 --- a/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java +++ b/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java @@ -1,7 +1,7 @@ package darkknight.jewelrycraft.block; -import java.io.IOException; import java.util.Random; + import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; @@ -80,16 +80,9 @@ public class BlockSmelter extends BlockContainer ItemStack metal = te.moltenMetal; ItemStack item = te.moltenMetal; if (Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.carpet)) metal.setItemDamage(15 - metal.getItemDamage()); - int color = 16777215; JewelryNBT.addMetal(item, metal); - try{ - color = ItemMoltenMetalBucket.color(item, 1); - } - catch(IOException e){ - e.printStackTrace(); - } - JewelrycraftMod.saveData.setString(i + " " + j + " " + k + " " + world.provider.dimensionId, Item.getIdFromItem(metal.getItem()) + ":" + metal.getItemDamage() + ":" + color); - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, i, j, k, Item.getIdFromItem(metal.getItem()), metal.getItemDamage(), color)); + JewelrycraftMod.saveData.setString(i + " " + j + " " + k + " " + world.provider.dimensionId, Item.getIdFromItem(metal.getItem()) + ":" + metal.getItemDamage()); + JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, i, j, k, Item.getIdFromItem(metal.getItem()), metal.getItemDamage())); world.setBlock(i, j, k, BlockList.moltenMetal, 0, 3); int quant = (int)(te.quantity * 10); if (quant == 1) world.setBlockMetadataWithNotify(i, j, k, 4, 3); diff --git a/src/main/java/darkknight/jewelrycraft/events/BucketHandler.java b/src/main/java/darkknight/jewelrycraft/events/BucketHandler.java index 871f26e..c11f2ee 100644 --- a/src/main/java/darkknight/jewelrycraft/events/BucketHandler.java +++ b/src/main/java/darkknight/jewelrycraft/events/BucketHandler.java @@ -1,79 +1,78 @@ -/** - * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com - * - * BuildCraft is distributed under the terms of the Minecraft Mod Public License - * 1.0, or MMPL. Please check the contents of the license located in - * http://www.mod-buildcraft.com/MMPL-1.0.txt - */ -package darkknight.jewelrycraft.events; - -import java.util.HashMap; -import java.util.Map; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.world.World; -import net.minecraftforge.event.entity.player.FillBucketEvent; -import cpw.mods.fml.common.eventhandler.Event.Result; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import darkknight.jewelrycraft.JewelrycraftMod; -import darkknight.jewelrycraft.block.BlockMoltenMetal; -import darkknight.jewelrycraft.util.JewelryNBT; - -public class BucketHandler -{ - public static BucketHandler INSTANCE = new BucketHandler(); - public Map buckets = new HashMap(); - - /** - * - */ - private BucketHandler() - {} - - /** - * @param event - */ - @SubscribeEvent - public void onBucketFill(FillBucketEvent event) - { - ItemStack result = fillCustomBucket(event.world, event.target); - if (result == null) return; - event.result = result; - event.setResult(Result.ALLOW); - } - - /** - * @param world - * @param pos - * @return - */ - private ItemStack fillCustomBucket(World world, MovingObjectPosition pos) - { - Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ); - Item bucket = buckets.get(block); - if (bucket != null && world.getBlock(pos.blockX, pos.blockY, pos.blockZ) != Blocks.air && world.getBlock(pos.blockX, pos.blockY, pos.blockZ) instanceof BlockMoltenMetal){ - world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ); - ItemStack item = new ItemStack(bucket); - String ingotData = JewelrycraftMod.saveData.getString(pos.blockX + " " + pos.blockY + " " + pos.blockZ + " " + world.provider.dimensionId); - if (ingotData != null && ingotData != ""){ - String[] splitData = ingotData.split(":"); - if (splitData.length == 3){ - int itemID, itemDamage; - try{ - itemID = Integer.parseInt(splitData[0]); - itemDamage = Integer.parseInt(splitData[1]); - Integer.parseInt(splitData[2]); - JewelryNBT.addMetal(item, new ItemStack(Item.getItemById(itemID), 1, itemDamage)); - } - catch(Exception e){ - e.printStackTrace(); - } - } - } - return item; - }else return null; - } +/** + * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License + * 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package darkknight.jewelrycraft.events; + +import java.util.HashMap; +import java.util.Map; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.player.FillBucketEvent; +import cpw.mods.fml.common.eventhandler.Event.Result; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.block.BlockMoltenMetal; +import darkknight.jewelrycraft.util.JewelryNBT; + +public class BucketHandler +{ + public static BucketHandler INSTANCE = new BucketHandler(); + public Map buckets = new HashMap(); + + /** + * + */ + private BucketHandler() + {} + + /** + * @param event + */ + @SubscribeEvent + public void onBucketFill(FillBucketEvent event) + { + ItemStack result = fillCustomBucket(event.world, event.target); + if (result == null) return; + event.result = result; + event.setResult(Result.ALLOW); + } + + /** + * @param world + * @param pos + * @return + */ + private ItemStack fillCustomBucket(World world, MovingObjectPosition pos) + { + Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ); + Item bucket = buckets.get(block); + if (bucket != null && world.getBlock(pos.blockX, pos.blockY, pos.blockZ) != Blocks.air && world.getBlock(pos.blockX, pos.blockY, pos.blockZ) instanceof BlockMoltenMetal){ + world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ); + ItemStack item = new ItemStack(bucket); + String ingotData = JewelrycraftMod.saveData.getString(pos.blockX + " " + pos.blockY + " " + pos.blockZ + " " + world.provider.dimensionId); + if (ingotData != null && ingotData != ""){ + String[] splitData = ingotData.split(":"); + if (splitData.length == 2){ + int itemID, itemDamage; + try{ + itemID = Integer.parseInt(splitData[0]); + itemDamage = Integer.parseInt(splitData[1]); + JewelryNBT.addMetal(item, new ItemStack(Item.getItemById(itemID), 1, itemDamage)); + } + catch(Exception e){ + e.printStackTrace(); + } + } + } + return item; + }else return null; + } } \ No newline at end of file diff --git a/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java index 1ffdeb7..f25e09e 100644 --- a/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java +++ b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java @@ -8,7 +8,9 @@ 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; @@ -18,6 +20,7 @@ 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.JewelrycraftUtil; import darkknight.jewelrycraft.util.Variables; public class ItemMoltenMetal extends Item @@ -49,92 +52,7 @@ public class ItemMoltenMetal extends Item @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; + if(JewelryNBT.ingot(stack) != null) return JewelrycraftUtil.getColor(JewelryNBT.ingot(stack)); + else return 0xFFFFFF; } } diff --git a/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java index b9a83c4..0f68283 100644 --- a/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java +++ b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java @@ -25,6 +25,7 @@ import darkknight.jewelrycraft.block.BlockList; import darkknight.jewelrycraft.network.PacketRequestLiquidData; import darkknight.jewelrycraft.network.PacketSendLiquidData; import darkknight.jewelrycraft.util.JewelryNBT; +import darkknight.jewelrycraft.util.JewelrycraftUtil; import darkknight.jewelrycraft.util.Variables; public class ItemMoltenMetalBucket extends Item { @@ -80,11 +81,7 @@ public class ItemMoltenMetalBucket extends Item { 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(); - } + if (tryPlaceContainedLiquid(par2World, i, j, k, stack) && !par3EntityPlayer.capabilities.isCreativeMode) return new ItemStack(Items.bucket); } } return stack; @@ -117,7 +114,7 @@ public class ItemMoltenMetalBucket extends Item { * @return * @throws IOException */ - public boolean tryPlaceContainedLiquid(World world, int x, int y, int z, ItemStack stack) throws IOException { + public boolean tryPlaceContainedLiquid(World world, int x, int y, int z, ItemStack stack) { if (BlockList.moltenMetal == Blocks.air) return false; else { Material material = world.getBlock(x, y, z).getMaterial(); @@ -126,12 +123,8 @@ public class ItemMoltenMetalBucket extends Item { else if (stack != null && JewelryNBT.ingot(stack) != null) { if (!world.isRemote && flag && !material.isLiquid()) world.func_147480_a(x, y, z, true); if (world.isRemote) { - 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)); - } else { - JewelrycraftMod.saveData.setString(x + " " + y + " " + z + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage() + ":" + world.rand.nextInt(16777216)); - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage(), world.rand.nextInt(16777216))); + JewelrycraftMod.saveData.setString(x + " " + y + " " + z + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage()); + JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage())); } world.setBlock(x, y, z, BlockList.moltenMetal, 0, 3); return true; @@ -192,7 +185,8 @@ public class ItemMoltenMetalBucket extends Item { */ @SideOnly(Side.CLIENT) public static int color(ItemStack stack, int pass) throws IOException { - if (pass == 1) return ItemMoltenMetal.color(stack, pass); + // System.out.println(JewelrycraftUtil.getColor(stack)); + if (pass == 1 && JewelryNBT.ingot(stack) != null) return JewelrycraftUtil.getColor(JewelryNBT.ingot(stack)); return 16777215; } diff --git a/src/main/java/darkknight/jewelrycraft/network/PacketRequestLiquidData.java b/src/main/java/darkknight/jewelrycraft/network/PacketRequestLiquidData.java index ebcfdf4..52440e2 100644 --- a/src/main/java/darkknight/jewelrycraft/network/PacketRequestLiquidData.java +++ b/src/main/java/darkknight/jewelrycraft/network/PacketRequestLiquidData.java @@ -1,82 +1,81 @@ -package darkknight.jewelrycraft.network; - -import io.netty.buffer.ByteBuf; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import darkknight.jewelrycraft.JewelrycraftMod; - -public class PacketRequestLiquidData implements IMessage, IMessageHandler -{ - int dimID, x, y, z; - - /** - * - */ - public PacketRequestLiquidData() - {} - - /** - * @param dimID - * @param x - * @param y - * @param z - */ - public PacketRequestLiquidData(int dimID, int x, int y, int z) - { - this.dimID = dimID; - this.x = x; - this.y = y; - this.z = z; - } - - /** - * @param message - * @param ctx - * @return - */ - @Override - public IMessage onMessage(PacketRequestLiquidData message, MessageContext ctx) - { - String data = JewelrycraftMod.saveData.getString(message.x + " " + message.y + " " + message.z + " " + message.dimID); - String[] splitData = data.split(":"); - IMessage replyPacket = null; - if (splitData.length == 3){ - int itemID, itemDamage, color; - try{ - itemID = Integer.parseInt(splitData[0]); - itemDamage = Integer.parseInt(splitData[1]); - color = Integer.parseInt(splitData[2]); - replyPacket = new PacketSendLiquidData(message, itemID, itemDamage, color); - } - catch(Exception e){ - e.printStackTrace(); - } - } - return replyPacket; - } - - /** - * @param buf - */ - @Override - public void fromBytes(ByteBuf buf) - { - dimID = buf.readInt(); - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); - } - - /** - * @param buf - */ - @Override - public void toBytes(ByteBuf buf) - { - buf.writeInt(dimID); - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); - } -} +package darkknight.jewelrycraft.network; + +import io.netty.buffer.ByteBuf; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import darkknight.jewelrycraft.JewelrycraftMod; + +public class PacketRequestLiquidData implements IMessage, IMessageHandler +{ + int dimID, x, y, z; + + /** + * + */ + public PacketRequestLiquidData() + {} + + /** + * @param dimID + * @param x + * @param y + * @param z + */ + public PacketRequestLiquidData(int dimID, int x, int y, int z) + { + this.dimID = dimID; + this.x = x; + this.y = y; + this.z = z; + } + + /** + * @param message + * @param ctx + * @return + */ + @Override + public IMessage onMessage(PacketRequestLiquidData message, MessageContext ctx) + { + String data = JewelrycraftMod.saveData.getString(message.x + " " + message.y + " " + message.z + " " + message.dimID); + String[] splitData = data.split(":"); + IMessage replyPacket = null; + if (splitData.length == 2){ + int itemID, itemDamage; + try{ + itemID = Integer.parseInt(splitData[0]); + itemDamage = Integer.parseInt(splitData[1]); + replyPacket = new PacketSendLiquidData(message, itemID, itemDamage); + } + catch(Exception e){ + e.printStackTrace(); + } + } + return replyPacket; + } + + /** + * @param buf + */ + @Override + public void fromBytes(ByteBuf buf) + { + dimID = buf.readInt(); + x = buf.readInt(); + y = buf.readInt(); + z = buf.readInt(); + } + + /** + * @param buf + */ + @Override + public void toBytes(ByteBuf buf) + { + buf.writeInt(dimID); + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + } +} diff --git a/src/main/java/darkknight/jewelrycraft/network/PacketSendLiquidData.java b/src/main/java/darkknight/jewelrycraft/network/PacketSendLiquidData.java index bad14e7..dcb265b 100644 --- a/src/main/java/darkknight/jewelrycraft/network/PacketSendLiquidData.java +++ b/src/main/java/darkknight/jewelrycraft/network/PacketSendLiquidData.java @@ -1,100 +1,96 @@ -package darkknight.jewelrycraft.network; - -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import darkknight.jewelrycraft.JewelrycraftMod; - -public class PacketSendLiquidData implements IMessage, IMessageHandler -{ - int dimID, x, y, z, itemID, itemMeta, color; - - /** - * - */ - public PacketSendLiquidData() - {} - - /** - * @param packet - * @param itemID - * @param itemMeta - * @param color - */ - public PacketSendLiquidData(PacketRequestLiquidData packet, int itemID, int itemMeta, int color) - { - dimID = packet.dimID; - x = packet.x; - y = packet.y; - z = packet.z; - this.itemID = itemID; - this.itemMeta = itemMeta; - this.color = color; - } - - /** - * @param dimID - * @param x - * @param y - * @param z - * @param itemID - * @param itemMeta - * @param color - */ - public PacketSendLiquidData(int dimID, int x, int y, int z, int itemID, int itemMeta, int color) - { - this.dimID = dimID; - this.x = x; - this.y = y; - this.z = z; - this.itemID = itemID; - this.itemMeta = itemMeta; - this.color = color; - } - - /** - * @param buf - */ - @Override - public void fromBytes(ByteBuf buf) - { - dimID = buf.readInt(); - x = buf.readInt(); - y = buf.readInt(); - z = buf.readInt(); - itemID = buf.readInt(); - itemMeta = buf.readInt(); - color = buf.readInt(); - } - - /** - * @param buf - */ - @Override - public void toBytes(ByteBuf buf) - { - buf.writeInt(dimID); - buf.writeInt(x); - buf.writeInt(y); - buf.writeInt(z); - buf.writeInt(itemID); - buf.writeInt(itemMeta); - buf.writeInt(color); - } - - /** - * @param message - * @param ctx - * @return - */ - @Override - public IMessage onMessage(PacketSendLiquidData message, MessageContext ctx) - { - JewelrycraftMod.clientData.setString(message.x + " " + message.y + " " + message.z + " " + message.dimID, message.itemID + ":" + message.itemMeta + ":" + message.color); - Minecraft.getMinecraft().theWorld.getBlock(message.x, message.y, message.z); - Minecraft.getMinecraft().theWorld.markBlockForUpdate(message.x, message.y, message.z); - return null; - } -} +package darkknight.jewelrycraft.network; + +import io.netty.buffer.ByteBuf; +import net.minecraft.client.Minecraft; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import darkknight.jewelrycraft.JewelrycraftMod; + +public class PacketSendLiquidData implements IMessage, IMessageHandler +{ + int dimID, x, y, z, itemID, itemMeta; + + /** + * + */ + public PacketSendLiquidData() + {} + + /** + * @param packet + * @param itemID + * @param itemMeta + * @param color + */ + public PacketSendLiquidData(PacketRequestLiquidData packet, int itemID, int itemMeta) + { + dimID = packet.dimID; + x = packet.x; + y = packet.y; + z = packet.z; + this.itemID = itemID; + this.itemMeta = itemMeta; + } + + /** + * @param dimID + * @param x + * @param y + * @param z + * @param itemID + * @param itemMeta + * @param color + */ + public PacketSendLiquidData(int dimID, int x, int y, int z, int itemID, int itemMeta) + { + this.dimID = dimID; + this.x = x; + this.y = y; + this.z = z; + this.itemID = itemID; + this.itemMeta = itemMeta; + } + + /** + * @param buf + */ + @Override + public void fromBytes(ByteBuf buf) + { + dimID = buf.readInt(); + x = buf.readInt(); + y = buf.readInt(); + z = buf.readInt(); + itemID = buf.readInt(); + itemMeta = buf.readInt(); + } + + /** + * @param buf + */ + @Override + public void toBytes(ByteBuf buf) + { + buf.writeInt(dimID); + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + buf.writeInt(itemID); + buf.writeInt(itemMeta); + } + + /** + * @param message + * @param ctx + * @return + */ + @Override + public IMessage onMessage(PacketSendLiquidData message, MessageContext ctx) + { + JewelrycraftMod.clientData.setString(message.x + " " + message.y + " " + message.z + " " + message.dimID, message.itemID + ":" + message.itemMeta); + Minecraft.getMinecraft().theWorld.getBlock(message.x, message.y, message.z); + Minecraft.getMinecraft().theWorld.markBlockForUpdate(message.x, message.y, message.z); + return null; + } +} diff --git a/src/main/java/darkknight/jewelrycraft/proxy/ClientProxy.java b/src/main/java/darkknight/jewelrycraft/proxy/ClientProxy.java index 01d1303..ba70925 100644 --- a/src/main/java/darkknight/jewelrycraft/proxy/ClientProxy.java +++ b/src/main/java/darkknight/jewelrycraft/proxy/ClientProxy.java @@ -1,5 +1,7 @@ package darkknight.jewelrycraft.proxy; +import java.util.logging.Level; + import net.minecraft.client.Minecraft; import net.minecraft.item.Item; import net.minecraftforge.client.MinecraftForgeClient; @@ -8,13 +10,12 @@ import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.registry.VillagerRegistry; -import cpw.mods.fml.relauncher.Side; +import darkknight.jewelrycraft.JewelrycraftMod; import darkknight.jewelrycraft.block.BlockList; import darkknight.jewelrycraft.block.render.BlockCrystalRenderer; import darkknight.jewelrycraft.client.InventoryTabVanilla; import darkknight.jewelrycraft.client.TabJewelry; import darkknight.jewelrycraft.client.TabRegistry; -import darkknight.jewelrycraft.client.gui.GuiHandler; import darkknight.jewelrycraft.entities.EntityHalfHeart; import darkknight.jewelrycraft.entities.EntityHeart; import darkknight.jewelrycraft.entities.renders.HeartRender; @@ -74,7 +75,8 @@ public class ClientProxy extends CommonProxy { TileEntityHandPedestalRender pedestalRender = new TileEntityHandPedestalRender(new ModelHandPedestal(Variables.PEDESTAL_TEXTURE), Variables.PEDESTAL_TEXTURE); TileEntityShadowHandRender shadowHandRender = new TileEntityShadowHandRender(new ModelShadowHand(Variables.SHADOW_HAND_TEXTURE), Variables.SHADOW_HAND_TEXTURE); - + + JewelrycraftMod.logger.log(Level.INFO, "Binding Tileentities to their Special Rendered"); ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySmelter.class, new TileEntitySmelterRender()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMolder.class, new TileEntityMolderRender()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityJewelrsCraftingTable.class, new TileEntityJewelrsCraftingTableRender()); @@ -84,6 +86,7 @@ public class ClientProxy extends CommonProxy ClientRegistry.bindTileEntitySpecialRenderer(TileEntityHandPedestal.class, pedestalRender); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityShadowHand.class, shadowHandRender); + JewelrycraftMod.logger.log(Level.INFO, "Registering Item Renderes"); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(BlockList.displayer), new ItemRender(new TileEntityDisplayerRender(), new TileEntityDisplayer(), new ModelDisplayer())); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(BlockList.jewelCraftingTable), new ItemRender(new TileEntityJewelrsCraftingTableRender(), new TileEntityJewelrsCraftingTable(), new ModelJewlersCraftingBench())); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(BlockList.smelter), new ItemRender(new TileEntitySmelterRender(), new TileEntitySmelter(), new ModelSmelter())); @@ -95,6 +98,7 @@ public class ClientProxy extends CommonProxy VillagerRegistry.instance().registerVillagerSkin(3000, Variables.VILLAGER_TEXTURE); + JewelrycraftMod.logger.log(Level.INFO, "Registering Entity Renders"); RenderingRegistry.registerEntityRenderingHandler(EntityHeart.class, new HeartRender(new ModelHeart(), 0.25F)); RenderingRegistry.registerEntityRenderingHandler(EntityHalfHeart.class, new HeartRender(new ModelHalfHeart(), 0.25F)); @@ -115,6 +119,8 @@ public class ClientProxy extends CommonProxy @Override public void postInit() - { + { + JewelrycraftMod.logger.log(Level.INFO, "Generating colors for each item"); + JewelrycraftUtil.generateColors(); } } diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java index e8beb57..4cf9ced 100644 --- a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java @@ -1,10 +1,22 @@ package darkknight.jewelrycraft.util; +import java.awt.image.BufferedImage; +import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import java.util.Random; + +import javax.imageio.ImageIO; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.IResourceManager; import net.minecraft.entity.EnumCreatureAttribute; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -13,6 +25,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; import net.minecraftforge.oredict.OreDictionary; @@ -20,240 +33,318 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import darkknight.jewelrycraft.JewelrycraftMod; import darkknight.jewelrycraft.api.Curse; import darkknight.jewelrycraft.block.BlockList; +import darkknight.jewelrycraft.item.ItemBaseJewelry; import darkknight.jewelrycraft.item.ItemList; import darkknight.jewelrycraft.random.WeightedRandomCurse; import darkknight.jewelrycraft.worldGen.Generation; -public class JewelrycraftUtil -{ - public static ArrayList objects = new ArrayList(); - public static ArrayList gem = new ArrayList(); - public static ArrayList jewelry = new ArrayList(); - public static ArrayList metal = new ArrayList(); - public static ArrayList ores = new ArrayList(); - public static HashMap oreToIngot = new HashMap(); - public static ArrayList jamcraftPlayers = new ArrayList(); - private static ArrayList items = new ArrayList(); - public static ArrayList structures = new ArrayList(); - public static Random rand = new Random(); - public static EnumCreatureAttribute HEART; - - /** - * Adds gems and jewelry to their appropriate list - */ - public static void addStuff() - { - // Jewels - for(int i = 0; i < 16; i++) - gem.add(new ItemStack(BlockList.crystal, 1, i)); - gem.add(new ItemStack(Blocks.redstone_block)); - gem.add(new ItemStack(Blocks.lapis_block)); - gem.add(new ItemStack(Blocks.obsidian)); - gem.add(new ItemStack(Items.diamond)); - gem.add(new ItemStack(Items.emerald)); - gem.add(new ItemStack(Items.ender_pearl)); - gem.add(new ItemStack(Items.nether_star)); - // Jewelry - jewelry.add(new ItemStack(ItemList.ring)); - jewelry.add(new ItemStack(ItemList.necklace)); - jewelry.add(new ItemStack(ItemList.bracelet)); - jewelry.add(new ItemStack(ItemList.earrings)); - for(Object item: GameData.getItemRegistry()){ - if (Loader.isModLoaded("Mantle") && ((Item)item).getUnlocalizedName().equals("Mantle:item.mantle.manual")) continue; - try{ - if (item != null && (Item)item != null && ((Item)item).getHasSubtypes() && FMLCommonHandler.instance().getSide() == Side.CLIENT){ - ((Item)item).getSubItems((Item)item, null, items); - }else objects.add(new ItemStack((Item)item)); - if (!items.isEmpty()) objects.addAll(items); - items.removeAll(items); - } - catch(Exception e){ - JewelrycraftMod.logger.info("Error, tried to add subtypes of item " + ((Item)item).getUnlocalizedName() + "\nItem is not added in the list."); - } - } - // Structures - try{ - for(Field f: Generation.class.getDeclaredFields()){ - Object obj = f.get(null); - if (obj instanceof WorldGenerator) structures.add((WorldGenerator)obj); - } - } - catch(IllegalAccessException e){ - throw new RuntimeException(e); - } - } - - public static WeightedRandomCurse[] getCurses(World world, EntityPlayer player, Random random) - { - WeightedRandomCurse[] curses = new WeightedRandomCurse[Curse.availableCurses.size()]; - for(int c = 0; c < Curse.availableCurses.size(); c++) - curses[c] = new WeightedRandomCurse(Curse.availableCurses.get(c), Curse.availableCurses.get(c).weight(world, player, random)); - return curses; - } - - /** - * Adds curse points to a player - * - * @param player the player to add the points to - * @param points amount of curse points - */ - public static void addCursePoints(EntityPlayer player, int points) - { - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - playerInfo.setInteger("cursePoints", playerInfo.hasKey("cursePoints") ? (playerInfo.getInteger("cursePoints") + points) : points); - playerInfo.setBoolean("playerCursePointsChanged", true); - } - - public static int getCursePoints(EntityPlayer player) - { - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - return playerInfo.getInteger("cursePoints"); - } - - /** - * Adds the UUID's of the jamcrafters in a list - */ - public static void jamcrafters() - { - jamcraftPlayers.add("d3214311-7550-4c9c-a372-d9292c10b8a6"); - jamcraftPlayers.add("a690119f-c4a2-4bd6-a99d-d63679abb328"); - jamcraftPlayers.add("de7c9903-51fa-4a24-88cd-48faf122ca36"); - jamcraftPlayers.add("70aeb298-3a7b-46da-a393-ab10df9359f2"); - jamcraftPlayers.add("6fbe603c-14bf-4085-afdd-abe592c26e7c"); - jamcraftPlayers.add("b0d21306-36bf-4d85-84df-a956d183c45a"); - jamcraftPlayers.add("1733a31f-01f9-4f4d-82aa-7de30ca810d3"); - jamcraftPlayers.add("4833eacf-1d94-49a7-9f89-4cf88d69dcf9"); - jamcraftPlayers.add("718cf671-9084-4e78-b91f-033e80aa11bf"); - jamcraftPlayers.add("bea5e0c4-85c4-454d-a081-e1eaae6895ee"); - jamcraftPlayers.add("7ecf3e2f-fedf-4f7e-8d24-6731d078db4f"); - jamcraftPlayers.add("1b11ad3a-f0ca-4695-a019-2d7e5d83a5fd"); - jamcraftPlayers.add("3ec9ac58-2f1b-4d3f-b4eb-3b875da877ae"); - jamcraftPlayers.add("cf9fa23f-205e-4eed-aba3-9f2848cd6a4d"); - jamcraftPlayers.add("91880caa-b032-48e3-bfe8-c2c7ed31824e"); - jamcraftPlayers.add("8d0b3804-f71c-4219-897b-8c315448ea7c"); - jamcraftPlayers.add("bbb87dbe-690f-4205-bdc5-72ffb8ebc29d"); - } - - /** - * Adds a random amount of modifiers to a list - * - * @param randValue maximum number of modifiers - * @return a list containing the random modifiers - */ - public static ArrayList addRandomModifiers(int randValue) - { - ArrayList list = new ArrayList(); - for(int i = 0; i < 2 + randValue; i++){ - ItemStack item = objects.get(new Random().nextInt(objects.size())); - item.stackSize = 1 + new Random().nextInt(2); - list.add(item); - } - return list; - } - - /** - * Links ores with their appropriate ingot - */ - public static void addMetals() - { - int index = 0; - while (index < OreDictionary.getOreNames().length){ - Iterator i = OreDictionary.getOres(OreDictionary.getOreNames()[index]).iterator(); - while (i.hasNext()){ - ItemStack nextStack = i.next(); - String stackName = nextStack.getItem().getUnlocalizedName().toLowerCase(); - if ((stackName.contains("ingot") || stackName.contains("alloy")) && !metal.contains(nextStack)) metal.add(nextStack); - if (nextStack.getItem().getUnlocalizedName().toLowerCase().contains("ore") && !ores.contains(nextStack)){ - ItemStack ingot = FurnaceRecipes.smelting().getSmeltingResult(nextStack); - if (ingot != null && (ingot.getItem().getUnlocalizedName().toLowerCase().contains("ingot") || ingot.getItem().getUnlocalizedName().toLowerCase().contains("alloy"))){ - ores.add(nextStack); - oreToIngot.put(nextStack, ingot); - JewelrycraftMod.logger.info(nextStack + " Adding " + nextStack.getDisplayName() + " with damage value " + nextStack.getItemDamage() + " and with " + nextStack.stackSize + " in stack"); - JewelrycraftMod.logger.info(ingot + " Adding ingot " + ingot.getDisplayName() + " with damage value " + ingot.getItemDamage() + " and with " + ingot.stackSize + " in stack\n"); - } - } - } - index++; - } - } - - /** - * Checks to see if the specified item is a gem - * - * @param item ItemStack containing the item - * @return is the item a gem - */ - public static boolean isGem(ItemStack item) - { - Iterator i = gem.iterator(); - while (i.hasNext()){ - ItemStack temp = i.next(); - if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) return true; - } - return false; - } - - /** - * Checks to see if the specified item is a metal - * - * @param item ItemStack containing the item - * @return is the item a metal - */ - public static boolean isMetal(ItemStack item) - { - Iterator i = metal.iterator(); - while (i.hasNext()){ - ItemStack temp = i.next(); - if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) return true; - } - return false; - } - - /** - * Checks to see if the specified item is a piece of jewelry - * - * @param item ItemStack containing the item - * @return is the item a piece of jewelry - */ - public static boolean isJewelry(ItemStack item) - { - Iterator i = jewelry.iterator(); - while (i.hasNext()){ - ItemStack temp = i.next(); - if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) return true; - } - return false; - } - - /** - * Checks to see if the specified item is an ore - * - * @param item ItemStack containing the item - * @return is the item an ore - */ - public static boolean isOre(ItemStack item) - { - Iterator i = ores.iterator(); - while (i.hasNext()){ - ItemStack temp = i.next(); - if (temp.getItem().equals(item.getItem()) && temp.getItemDamage() == item.getItemDamage()) return true; - } - return false; - } - - /** - * Gets the ingot from the ore - * - * @param ore the ore - * @return the ingot - */ - public static ItemStack getIngotFromOre(ItemStack ore) - { - for(ItemStack ores: JewelrycraftUtil.oreToIngot.keySet()) - if (ores.getItem().equals(ore.getItem()) && ores.getItemDamage() == ore.getItemDamage()) return oreToIngot.get(ores); - return null; - } +public class JewelrycraftUtil { + public static ArrayList objects = new ArrayList(); + public static ArrayList gem = new ArrayList(); + public static ArrayList jewelry = new ArrayList(); + public static ArrayList metal = new ArrayList(); + public static ArrayList ores = new ArrayList(); + public static HashMap oreToIngot = new HashMap(); + public static HashMap colors = new HashMap(); + public static ArrayList jamcraftPlayers = new ArrayList(); + private static ArrayList items = new ArrayList(); + public static ArrayList structures = new ArrayList(); + public static Random rand = new Random(); + public static EnumCreatureAttribute HEART; + + /** + * Adds gems and jewelry to their appropriate list + */ + public static void addStuff() { + // Jewels + for (int i = 0; i < 16; i++) + gem.add(new ItemStack(BlockList.crystal, 1, i)); + gem.add(new ItemStack(Blocks.redstone_block)); + gem.add(new ItemStack(Blocks.lapis_block)); + gem.add(new ItemStack(Blocks.obsidian)); + gem.add(new ItemStack(Items.diamond)); + gem.add(new ItemStack(Items.emerald)); + gem.add(new ItemStack(Items.ender_pearl)); + gem.add(new ItemStack(Items.nether_star)); + // Jewelry + jewelry.add(new ItemStack(ItemList.ring)); + jewelry.add(new ItemStack(ItemList.necklace)); + jewelry.add(new ItemStack(ItemList.bracelet)); + jewelry.add(new ItemStack(ItemList.earrings)); + for (Object item : GameData.getItemRegistry()) { + if (Loader.isModLoaded("Mantle") && ((Item) item).getUnlocalizedName().equals("Mantle:item.mantle.manual")) continue; + try { + if (item != null && (Item) item != null && ((Item) item).getHasSubtypes() && FMLCommonHandler.instance().getSide() == Side.CLIENT) { + ((Item) item).getSubItems((Item) item, null, items); + } else objects.add(new ItemStack((Item) item)); + if (!items.isEmpty()) objects.addAll(items); + items.removeAll(items); + } catch (Exception e) { + JewelrycraftMod.logger.info("Error, tried to add subtypes of item " + ((Item) item).getUnlocalizedName() + "\nItem is not added in the list."); + } + } + // Structures + try { + for (Field f : Generation.class.getDeclaredFields()) { + Object obj = f.get(null); + if (obj instanceof WorldGenerator) structures.add((WorldGenerator) obj); + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + @SideOnly(Side.CLIENT) + public static void generateColors() { + for (Object item : GameData.getItemRegistry()) { + if (Loader.isModLoaded("Mantle") && ((Item) item).getUnlocalizedName().equals("Mantle:item.mantle.manual")) continue; + try { + if (item != null && (Item) item != null && ((Item) item).getHasSubtypes() && FMLCommonHandler.instance().getSide() == Side.CLIENT) { + ((Item) item).getSubItems((Item) item, null, items); + } else { + ItemStack it = new ItemStack((Item) item); + colors.put(it, color(it, 0)); + } + if (!items.isEmpty()) for (ItemStack it : items) + colors.put(it, color(it, 0)); + items.removeAll(items); + } catch (Exception e) { + JewelrycraftMod.logger.info("Error, tried to add subtypes of item " + ((Item) item).getUnlocalizedName() + "\nItem is not added in the list."); + } + } + } + + @SideOnly(Side.CLIENT) + public static int getColor(ItemStack item) { + for (ItemStack stack : colors.keySet()) + if (item.getItem().equals(stack.getItem()) && item.getItemDamage() == stack.getItemDamage()) + return colors.get(stack); + return 0xFFFFFF; + } + + @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 && Item.getIdFromItem(stack.getItem()) > 0 && stack.getIconIndex() != null && stack.getItem().getColorFromItemStack(stack, pass) == 16777215) { + try { + ingot = ItemBaseJewelry.getLocation(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); + } + return getMostCommonColour(m); + } else return stack.getItem().getColorFromItemStack(stack, pass); + } + + @SideOnly(Side.CLIENT) + 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; + } + + @SideOnly(Side.CLIENT) + public static boolean isGray(int[] rgbArr) { + int rgbSum = rgbArr[0] + rgbArr[1] + rgbArr[2]; + if (rgbSum > 0 && rgbSum < 256 * 3) return false; + return true; + } + + public static WeightedRandomCurse[] getCurses(World world, EntityPlayer player, Random random) { + WeightedRandomCurse[] curses = new WeightedRandomCurse[Curse.availableCurses.size()]; + for (int c = 0; c < Curse.availableCurses.size(); c++) + curses[c] = new WeightedRandomCurse(Curse.availableCurses.get(c), Curse.availableCurses.get(c).weight(world, player, random)); + return curses; + } + + /** + * Adds curse points to a player + * + * @param player + * the player to add the points to + * @param points + * amount of curse points + */ + public static void addCursePoints(EntityPlayer player, int points) { + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + playerInfo.setInteger("cursePoints", playerInfo.hasKey("cursePoints") ? (playerInfo.getInteger("cursePoints") + points) : points); + playerInfo.setBoolean("playerCursePointsChanged", true); + } + + public static int getCursePoints(EntityPlayer player) { + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + return playerInfo.getInteger("cursePoints"); + } + + /** + * Adds the UUID's of the jamcrafters in a list + */ + public static void jamcrafters() { + jamcraftPlayers.add("d3214311-7550-4c9c-a372-d9292c10b8a6"); + jamcraftPlayers.add("a690119f-c4a2-4bd6-a99d-d63679abb328"); + jamcraftPlayers.add("de7c9903-51fa-4a24-88cd-48faf122ca36"); + jamcraftPlayers.add("70aeb298-3a7b-46da-a393-ab10df9359f2"); + jamcraftPlayers.add("6fbe603c-14bf-4085-afdd-abe592c26e7c"); + jamcraftPlayers.add("b0d21306-36bf-4d85-84df-a956d183c45a"); + jamcraftPlayers.add("1733a31f-01f9-4f4d-82aa-7de30ca810d3"); + jamcraftPlayers.add("4833eacf-1d94-49a7-9f89-4cf88d69dcf9"); + jamcraftPlayers.add("718cf671-9084-4e78-b91f-033e80aa11bf"); + jamcraftPlayers.add("bea5e0c4-85c4-454d-a081-e1eaae6895ee"); + jamcraftPlayers.add("7ecf3e2f-fedf-4f7e-8d24-6731d078db4f"); + jamcraftPlayers.add("1b11ad3a-f0ca-4695-a019-2d7e5d83a5fd"); + jamcraftPlayers.add("3ec9ac58-2f1b-4d3f-b4eb-3b875da877ae"); + jamcraftPlayers.add("cf9fa23f-205e-4eed-aba3-9f2848cd6a4d"); + jamcraftPlayers.add("91880caa-b032-48e3-bfe8-c2c7ed31824e"); + jamcraftPlayers.add("8d0b3804-f71c-4219-897b-8c315448ea7c"); + jamcraftPlayers.add("bbb87dbe-690f-4205-bdc5-72ffb8ebc29d"); + } + + /** + * Adds a random amount of modifiers to a list + * + * @param randValue + * maximum number of modifiers + * @return a list containing the random modifiers + */ + public static ArrayList addRandomModifiers(int randValue) { + ArrayList list = new ArrayList(); + for (int i = 0; i < 2 + randValue; i++) { + ItemStack item = objects.get(new Random().nextInt(objects.size())); + item.stackSize = 1 + new Random().nextInt(2); + list.add(item); + } + return list; + } + + /** + * Links ores with their appropriate ingot + */ + public static void addMetals() { + int index = 0; + while (index < OreDictionary.getOreNames().length) { + Iterator i = OreDictionary.getOres(OreDictionary.getOreNames()[index]).iterator(); + while (i.hasNext()) { + ItemStack nextStack = i.next(); + String stackName = nextStack.getItem().getUnlocalizedName().toLowerCase(); + if ((stackName.contains("ingot") || stackName.contains("alloy")) && !metal.contains(nextStack)) metal.add(nextStack); + if (nextStack.getItem().getUnlocalizedName().toLowerCase().contains("ore") && !ores.contains(nextStack)) { + ItemStack ingot = FurnaceRecipes.smelting().getSmeltingResult(nextStack); + if (ingot != null && (ingot.getItem().getUnlocalizedName().toLowerCase().contains("ingot") || ingot.getItem().getUnlocalizedName().toLowerCase().contains("alloy"))) { + ores.add(nextStack); + oreToIngot.put(nextStack, ingot); + JewelrycraftMod.logger.info(nextStack + " Adding " + nextStack.getDisplayName() + " with damage value " + nextStack.getItemDamage() + " and with " + nextStack.stackSize + " in stack"); + JewelrycraftMod.logger.info(ingot + " Adding ingot " + ingot.getDisplayName() + " with damage value " + ingot.getItemDamage() + " and with " + ingot.stackSize + " in stack\n"); + } + } + } + index++; + } + } + + /** + * Checks to see if the specified item is a gem + * + * @param item + * ItemStack containing the item + * @return is the item a gem + */ + public static boolean isGem(ItemStack item) { + Iterator i = gem.iterator(); + while (i.hasNext()) { + ItemStack temp = i.next(); + if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) return true; + } + return false; + } + + /** + * Checks to see if the specified item is a metal + * + * @param item + * ItemStack containing the item + * @return is the item a metal + */ + public static boolean isMetal(ItemStack item) { + Iterator i = metal.iterator(); + while (i.hasNext()) { + ItemStack temp = i.next(); + if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) return true; + } + return false; + } + + /** + * Checks to see if the specified item is a piece of jewelry + * + * @param item + * ItemStack containing the item + * @return is the item a piece of jewelry + */ + public static boolean isJewelry(ItemStack item) { + Iterator i = jewelry.iterator(); + while (i.hasNext()) { + ItemStack temp = i.next(); + if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) return true; + } + return false; + } + + /** + * Checks to see if the specified item is an ore + * + * @param item + * ItemStack containing the item + * @return is the item an ore + */ + public static boolean isOre(ItemStack item) { + Iterator i = ores.iterator(); + while (i.hasNext()) { + ItemStack temp = i.next(); + if (temp.getItem().equals(item.getItem()) && temp.getItemDamage() == item.getItemDamage()) return true; + } + return false; + } + + /** + * Gets the ingot from the ore + * + * @param ore + * the ore + * @return the ingot + */ + public static ItemStack getIngotFromOre(ItemStack ore) { + for (ItemStack ores : JewelrycraftUtil.oreToIngot.keySet()) + if (ores.getItem().equals(ore.getItem()) && ores.getItemDamage() == ore.getItemDamage()) return oreToIngot.get(ores); + return null; + } } diff --git a/src/main/java/darkknight/jewelrycraft/worldGen/WorldGenStructure2.java b/src/main/java/darkknight/jewelrycraft/worldGen/WorldGenStructure2.java index b7662bb..5f094e4 100644 --- a/src/main/java/darkknight/jewelrycraft/worldGen/WorldGenStructure2.java +++ b/src/main/java/darkknight/jewelrycraft/worldGen/WorldGenStructure2.java @@ -45,23 +45,12 @@ public class WorldGenStructure2 extends WorldGenerator { world.setBlock(x, y, z, Blocks.air); ItemStack stack = new ItemStack(ItemList.bucket); JewelryNBT.addMetal(stack, JewelrycraftUtil.metal.get(rand.nextInt(JewelrycraftUtil.metal.size()))); - try { - if (stack != null && JewelryNBT.ingot(stack) != null) { - if (!world.isRemote) world.func_147480_a(x, y, z, true); - if (world.isRemote) { - int color = ItemMoltenMetalBucket.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)); - } - else{ - JewelrycraftMod.saveData.setString(x + " " + y + " " + z + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage() + ":" + rand.nextInt(16777216)); - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage(), rand.nextInt(16777216))); - } - System.out.println(x + " " + y + " " + z); - world.setBlock(x, y, z, BlockList.moltenMetal, 0, 3); - } - } catch (IOException e) { - e.printStackTrace(); + if (stack != null && JewelryNBT.ingot(stack) != null) { + if (!world.isRemote) world.func_147480_a(x, y, z, true); + JewelrycraftMod.saveData.setString(x + " " + y + " " + z + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage()); + JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage())); + System.out.println(x + " " + y + " " + z); + world.setBlock(x, y, z, BlockList.moltenMetal, 0, 3); } return true; } diff --git a/src/main/java/darkknight/jewelrycraft/worldGen/WorldGenStructure5.java b/src/main/java/darkknight/jewelrycraft/worldGen/WorldGenStructure5.java index 5518ef4..77ce6c1 100644 --- a/src/main/java/darkknight/jewelrycraft/worldGen/WorldGenStructure5.java +++ b/src/main/java/darkknight/jewelrycraft/worldGen/WorldGenStructure5.java @@ -76,23 +76,11 @@ public class WorldGenStructure5 extends WorldGenerator { if (rand.nextInt(5) == 0) { ItemStack stack = new ItemStack(ItemList.bucket); JewelryNBT.addMetal(stack, new ItemStack(Items.gold_ingot)); - try { - if (stack != null && JewelryNBT.ingot(stack) != null) { - if (!world.isRemote) world.func_147480_a(x, y, z, true); - if (world.isRemote) { - int color = ItemMoltenMetalBucket.color(stack, 1); - JewelrycraftMod.saveData.setString((x + 1) + " " + (y + 2) + " " + (z - 2) + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage() + ":" + color); - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x + 1, y + 2, z - 2, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage(), color)); - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestLiquidData(Minecraft.getMinecraft().theWorld.provider.dimensionId, x + 1, y + 2, z - 2)); - } - else{ - JewelrycraftMod.saveData.setString(x + " " + y + " " + z + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage() + ":" + rand.nextInt(16777216)); - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage(), rand.nextInt(16777216))); - } - world.setBlock(x + 1, y + 2, z - 2, BlockList.moltenMetal, 0, 3); - } - } catch (IOException e) { - e.printStackTrace(); + if (stack != null && JewelryNBT.ingot(stack) != null) { + if (!world.isRemote) world.func_147480_a(x, y, z, true); + JewelrycraftMod.saveData.setString((x + 1) + " " + (y + 2) + " " + (z - 2) + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage()); + JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x + 1, y + 2, z - 2, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage())); + world.setBlock(x + 1, y + 2, z - 2, BlockList.moltenMetal, 0, 3); } } else if (rand.nextBoolean()) world.setBlock(x + 1, y + 2, z - 2, Blocks.lava, 0, 3); else world.setBlock(x + 1, y + 2, z - 2, Blocks.water, 0, 3); -- cgit v1.2.3