From cdbbd891c43e082a36a32e49420bf87b6edd28e0 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Wed, 4 Sep 2019 22:24:39 -0400 Subject: More affix work --- .../jewelrycraft/util/JewelrycraftUtil.java | 95 ++++++++++++++++++---- 1 file changed, 81 insertions(+), 14 deletions(-) (limited to 'src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java') diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java index cdcdd12..1592609 100755 --- a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java @@ -6,6 +6,7 @@ import java.util.*; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.affixes.AffixMods; import darkknight.jewelrycraft.api.Curse; import darkknight.jewelrycraft.block.BlockList; import darkknight.jewelrycraft.item.ItemList; @@ -45,14 +46,14 @@ public class JewelrycraftUtil { 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 HEARTS; + private static Item[] jewelryTypes; + /** * Adds gems and jewelry to their appropriate lists */ @@ -111,9 +112,12 @@ public class JewelrycraftUtil { @SideOnly(Side.CLIENT) public static int getColor(ItemStack item) { for (ItemStack stack : colors.keySet()) { - if (item != null && item.getItem() != null && stack.getItem() != null - && item.getItem().equals(stack.getItem()) && item.getItemDamage() == stack.getItemDamage()) { - return colors.get(stack); + if (item != null && item.getItem() != null && stack.getItem() != null) { + if (item.getItem().equals(stack.getItem())) { + if (item.getItemDamage() == stack.getItemDamage()) { + return colors.get(stack); + } + } } } @@ -123,9 +127,10 @@ public class JewelrycraftUtil { @SideOnly(Side.CLIENT) public static int color(ItemStack stack, int pass) { if (stack != null) { - if (Item.getIdFromItem(stack.getItem()) > 0 - && stack.getItem().getColorFromItemStack(stack, pass) == 16777215) { - return (int) Math.random() * 16777215; + if (Item.getIdFromItem(stack.getItem()) > 0) { + if (stack.getItem().getColorFromItemStack(stack, pass) == 16777215) { + return (int) Math.random() * 16777215; + } } return stack.getItem().getColorFromItemStack(stack, pass); @@ -159,7 +164,9 @@ public class JewelrycraftUtil { TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); - if (texturemanager.getResourceLocation(item.getItemSpriteNumber()).toString().contains("items")) { + String textureBase = texturemanager.getResourceLocation(item.getItemSpriteNumber()).toString(); + + if (textureBase.contains("items")) { textureLocation = new ResourceLocation(domain.toLowerCase(), "textures/items/" + texture); } else { textureLocation = new ResourceLocation(domain.toLowerCase(), "textures/blocks/" + texture); @@ -169,8 +176,11 @@ public class JewelrycraftUtil { } private static boolean isValidBlockFromItem(ItemStack item) { - return !(Block.getBlockFromItem(item.getItem()) instanceof BlockAir) && !Block.getBlockFromItem(item.getItem()) - .getIcon(0, item.getItemDamage()).getIconName().equals("soul_sand"); + boolean isAirBlock = Block.getBlockFromItem(item.getItem()) instanceof BlockAir; + boolean isSoulSand = Block.getBlockFromItem(item.getItem()).getIcon(0, item.getItemDamage()).getIconName() + .equals("soul_sand"); + + return !(isAirBlock || isSoulSand); } @SideOnly(Side.CLIENT) @@ -207,10 +217,11 @@ public class JewelrycraftUtil { NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); int cursePoints; - if (playerInfo.hasKey("cursePoints")) + if (playerInfo.hasKey("cursePoints")) { cursePoints = (playerInfo.getInteger("cursePoints") + points); - else + } else { cursePoints = points; + } playerInfo.setInteger("cursePoints", cursePoints); @@ -257,7 +268,7 @@ public class JewelrycraftUtil { ArrayList list = new ArrayList<>(); for (int i = 0; i < 2 + randValue; i++) { - ItemStack item = objects.get(new Random().nextInt(objects.size())); + ItemStack item = getRandomObject(); item.stackSize = 1 + new Random().nextInt(2); @@ -310,6 +321,7 @@ public class JewelrycraftUtil { private static boolean isItemStackIn(ItemStack item, Iterator i) { while (i.hasNext()) { ItemStack temp = i.next(); + if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) { return true; } @@ -358,4 +370,59 @@ public class JewelrycraftUtil { public static boolean isAchievementUnlocked(EntityPlayer player, Achievement achievement) { return ((EntityPlayerMP) player).func_147099_x().hasAchievementUnlocked(achievement); } + + public static ItemStack generateJewelery(Random random) { + return generateJewelery(random.nextInt(4), random); + } + + public static ItemStack generateJewelery(int type, Random random) { + if (jewelryTypes == null) { + jewelryTypes = new Item[] { ItemList.ring, ItemList.necklace, ItemList.bracelet, ItemList.earrings }; + } + + int effType = Math.max(0, Math.min(3, type)); + + ItemStack jewelry = new ItemStack(jewelryTypes[effType]); + + if (JewelrycraftUtil.metal.size() > 0) { + ItemStack ingot = getRandomMetal(random); + + JewelryNBT.addMetal(jewelry, ingot); + } + + if (JewelrycraftUtil.objects.size() > 0 && random.nextInt(4) != 0) { + ArrayList modifiers = JewelrycraftUtil.addRandomModifiers(random.nextInt(4)); + + JewelryNBT.addModifiers(jewelry, modifiers); + } + + if (JewelrycraftUtil.gem.size() > 0 && random.nextInt(4) != 0) { + ItemStack gem = getRandomGem(random); + + JewelryNBT.addGem(jewelry, gem); + } + + String prefix = AffixMods.pickPrefix(random); + String suffix = AffixMods.pickSuffix(random); + + if (random.nextBoolean()) + JewelryNBT.addPrefix(jewelry, prefix); + + if (random.nextBoolean()) + JewelryNBT.addSuffix(jewelry, suffix); + + return jewelry; + } + + public static ItemStack getRandomGem(Random random) { + return JewelrycraftUtil.gem.get(random.nextInt(JewelrycraftUtil.gem.size())); + } + + public static ItemStack getRandomMetal(Random random) { + return JewelrycraftUtil.metal.get(random.nextInt(JewelrycraftUtil.metal.size())); + } + + public static ItemStack getRandomObject() { + return objects.get(new Random().nextInt(objects.size())); + } } -- cgit v1.2.3