diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-08-22 20:51:35 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-08-22 20:51:35 -0400 |
| commit | f242b3b9e2d62cc2263e9e9288c9feb9613e8132 (patch) | |
| tree | c3fa648e9b44594fbda16f53c5ebd94c5fa4cd21 /src/main/java/darkknight/jewelrycraft/util | |
| parent | 20bef6e26d948698398bd16aeab8c9e6b89110e4 (diff) | |
Update
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/util')
| -rwxr-xr-x | src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java | 216 | ||||
| -rwxr-xr-x | src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java | 29 |
2 files changed, 159 insertions, 86 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java index 3d42750..17090ab 100755 --- a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java @@ -11,12 +11,14 @@ public class JewelryNBT { public static void addItem(ItemStack item, ItemStack target) {
if (target != null) {
NBTTagCompound itemStackData;
- if (item.hasTagCompound())
+
+ if (item.hasTagCompound()) {
itemStackData = item.getTagCompound();
- else {
+ } else {
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
+
NBTTagCompound targetNBT = new NBTTagCompound();
target.writeToNBT(targetNBT);
itemStackData.setTag("target", targetNBT);
@@ -31,12 +33,14 @@ public class JewelryNBT { */
public static void addMetal(ItemStack item, ItemStack metal) {
NBTTagCompound itemStackData;
- if (item.hasTagCompound())
+
+ if (item.hasTagCompound()) {
itemStackData = item.getTagCompound();
- else {
+ } else {
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
+
if (metal != null) {
NBTTagCompound ingotNBT = new NBTTagCompound();
metal.writeToNBT(ingotNBT);
@@ -53,12 +57,14 @@ public class JewelryNBT { public static void addGem(ItemStack item, ItemStack gem) {
if (gem != null) {
NBTTagCompound itemStackData;
- if (item.hasTagCompound())
+
+ if (item.hasTagCompound()) {
itemStackData = item.getTagCompound();
- else {
+ } else {
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
+
NBTTagCompound gemNBT = new NBTTagCompound();
gem.writeToNBT(gemNBT);
itemStackData.setTag("gem", gemNBT);
@@ -74,17 +80,20 @@ public class JewelryNBT { public static void addModifiers(ItemStack item, ArrayList<ItemStack> modifier) {
if (modifier != null) {
NBTTagCompound itemStackData;
- if (item.hasTagCompound())
+
+ if (item.hasTagCompound()) {
itemStackData = item.getTagCompound();
- else {
+ } else {
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
+
for (int i = 0; i < modifier.size(); i++) {
NBTTagCompound modifierNBT = new NBTTagCompound();
modifier.get(i).writeToNBT(modifierNBT);
itemStackData.setTag("modifier" + i, modifierNBT);
}
+
itemStackData.setInteger("modifierSize", modifier.size());
}
}
@@ -95,12 +104,14 @@ public class JewelryNBT { */
public static void addIngotColor(ItemStack item, int color) {
NBTTagCompound itemStackData;
- if (item.hasTagCompound())
+
+ if (item.hasTagCompound()) {
itemStackData = item.getTagCompound();
- else {
+ } else {
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
+
itemStackData.setInteger("ingotColor", color);
}
@@ -111,12 +122,14 @@ public class JewelryNBT { */
public static void addGemColor(ItemStack item, int color) {
NBTTagCompound itemStackData;
- if (item.hasTagCompound())
+
+ if (item.hasTagCompound()) {
itemStackData = item.getTagCompound();
- else {
+ } else {
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
+
itemStackData.setInteger("gemColor", color);
}
@@ -128,14 +141,18 @@ public class JewelryNBT { */
public static boolean hasTag(ItemStack item, String tag) {
NBTTagCompound itemStackData;
- if (item.hasTagCompound())
+
+ if (item.hasTagCompound()) {
itemStackData = item.getTagCompound();
- else {
+ } else {
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
- if (itemStackData.hasKey(tag))
+
+ if (itemStackData.hasKey(tag)) {
return true;
+ }
+
return false;
}
@@ -145,9 +162,14 @@ public class JewelryNBT { * @return
*/
public static boolean isGemX(ItemStack stack, ItemStack gem) {
- if (gem(stack) != null && gem(stack).getItem() == gem.getItem()
- && gem(stack).getItemDamage() == gem.getItemDamage())
- return true;
+ if (gem(stack) != null) {
+ if (gem(stack).getItem() == gem.getItem()) {
+ if (gem(stack).getItemDamage() == gem.getItemDamage()) {
+ return true;
+ }
+ }
+ }
+
return false;
}
@@ -159,28 +181,40 @@ public class JewelryNBT { public static boolean doesModifierExist(ItemStack stack, ItemStack modifier) {
if (modifier(stack) != null) {
ArrayList<ItemStack> list = modifier(stack);
- for (int i = 0; i < list.size(); i++)
- if (list.get(i).getItem() == modifier.getItem()
- && list.get(i).getItemDamage() == modifier.getItemDamage())
- return true;
+
+ for (int i = 0; i < list.size(); i++) {
+ if (list.get(i).getItem() == modifier.getItem()) {
+ if (list.get(i).getItemDamage() == modifier.getItemDamage()) {
+ return true;
+ }
+ }
+ }
}
+
return false;
}
public static int modifierSize(ItemStack stack, ItemStack modifier) {
if (modifier(stack) != null) {
ArrayList<ItemStack> list = modifier(stack);
- for (int i = 0; i < list.size(); i++)
- if (list.get(i).getItem() == modifier.getItem()
- && list.get(i).getItemDamage() == modifier.getItemDamage())
- return list.get(i).stackSize;
+
+ for (int i = 0; i < list.size(); i++) {
+ if (list.get(i).getItem() == modifier.getItem()) {
+ if (list.get(i).getItemDamage() == modifier.getItemDamage()) {
+ return list.get(i).stackSize;
+ }
+ }
+ }
}
+
return -1;
}
public static int numberOfModifiers(ItemStack stack) {
- if (modifier(stack) != null)
+ if (modifier(stack) != null) {
return modifier(stack).size();
+ }
+
return -1;
}
@@ -190,21 +224,34 @@ public class JewelryNBT { * @return
*/
public static boolean isIngotX(ItemStack stack, ItemStack ingot) {
- if (ingot(stack) != null && ingot(stack).getItem() == ingot.getItem()
- && ingot(stack).getItemDamage() == ingot.getItemDamage())
- return true;
+ if (ingot(stack) != null) {
+ if (ingot(stack).getItem() == ingot.getItem()) {
+ if (ingot(stack).getItemDamage() == ingot.getItemDamage())
+ return true;
+ }
+ }
+
return false;
}
// TODO Return components based on NBT
public static ItemStack item(ItemStack stack) {
- if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound()
- && stack.getTagCompound().hasKey("target")) {
- NBTTagCompound itemNBT = (NBTTagCompound) stack.getTagCompound().getTag("target");
- ItemStack target = new ItemStack(Item.getItemById(0), 0, 0);
- target.readFromNBT(itemNBT);
- return target;
+ if (stack != null) {
+ if (stack != new ItemStack(Item.getItemById(0), 0, 0)) {
+ if (stack.hasTagCompound()) {
+ if (stack.getTagCompound().hasKey("target")) {
+ NBTTagCompound itemNBT = (NBTTagCompound) stack.getTagCompound().getTag("target");
+
+ ItemStack target = new ItemStack(Item.getItemById(0), 0, 0);
+
+ target.readFromNBT(itemNBT);
+
+ return target;
+ }
+ }
+ }
}
+
return null;
}
@@ -213,13 +260,20 @@ public class JewelryNBT { * @return
*/
public static ItemStack gem(ItemStack stack) {
- if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound()
- && stack.getTagCompound().hasKey("gem")) {
- NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("gem");
- ItemStack gem = new ItemStack(Item.getItemById(0), 0, 0);
- gem.readFromNBT(jewelNBT);
- return gem;
+ if (stack != null) {
+ if (stack != new ItemStack(Item.getItemById(0), 0, 0)) {
+ if (stack.hasTagCompound() && stack.getTagCompound().hasKey("gem")) {
+ NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("gem");
+
+ ItemStack gem = new ItemStack(Item.getItemById(0), 0, 0);
+
+ gem.readFromNBT(jewelNBT);
+
+ return gem;
+ }
+ }
}
+
return null;
}
@@ -228,17 +282,28 @@ public class JewelryNBT { * @return
*/
public static ArrayList<ItemStack> modifier(ItemStack stack) {
- if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound()) {
- int size = stack.getTagCompound().getInteger("modifierSize");
- ArrayList<ItemStack> list = new ArrayList<>();
- for (int i = 0; i < size; i++) {
- ItemStack modifier = new ItemStack(Item.getItemById(0), 0, 0);
- NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier" + i);
- modifier.readFromNBT(modifierNBT);
- list.add(modifier);
+ if (stack != null) {
+ if (stack != new ItemStack(Item.getItemById(0), 0, 0)) {
+ if (stack.hasTagCompound()) {
+ int size = stack.getTagCompound().getInteger("modifierSize");
+
+ ArrayList<ItemStack> list = new ArrayList<>();
+
+ for (int i = 0; i < size; i++) {
+ ItemStack modifier = new ItemStack(Item.getItemById(0), 0, 0);
+
+ NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier" + i);
+
+ modifier.readFromNBT(modifierNBT);
+
+ list.add(modifier);
+ }
+
+ return list;
+ }
}
- return list;
}
+
return null;
}
@@ -247,13 +312,22 @@ public class JewelryNBT { * @return
*/
public static ItemStack ingot(ItemStack stack) {
- if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound()
- && stack.getTagCompound().hasKey("ingot")) {
- NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot");
- ItemStack ingot = new ItemStack(Item.getItemById(0), 0, 0);
- ingot.readFromNBT(ingotNBT);
- return ingot;
+ if (stack != null) {
+ if (stack != new ItemStack(Item.getItemById(0), 0, 0)) {
+ if (stack.hasTagCompound()) {
+ if (stack.getTagCompound().hasKey("ingot")) {
+ NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot");
+
+ ItemStack ingot = new ItemStack(Item.getItemById(0), 0, 0);
+
+ ingot.readFromNBT(ingotNBT);
+
+ return ingot;
+ }
+ }
+ }
}
+
return null;
}
@@ -262,9 +336,16 @@ public class JewelryNBT { * @return
*/
public static int ingotColor(ItemStack stack) {
- if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound()
- && stack.getTagCompound().hasKey("ingotColor"))
- return stack.getTagCompound().getInteger("ingotColor");
+ if (stack != null) {
+ if (stack != new ItemStack(Item.getItemById(0), 0, 0)) {
+ if (stack.hasTagCompound()) {
+ if (stack.getTagCompound().hasKey("ingotColor")) {
+ return stack.getTagCompound().getInteger("ingotColor");
+ }
+ }
+ }
+ }
+
return 16777215;
}
@@ -274,10 +355,15 @@ public class JewelryNBT { * @return
*/
public static int gemColor(ItemStack stack) {
- if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound()
- && stack.getTagCompound().hasKey("gemColor"))
- return stack.getTagCompound().getInteger("gemColor");
+ if (stack != null) {
+ if (stack != new ItemStack(Item.getItemById(0), 0, 0)) {
+ if (stack.hasTagCompound()) {
+ if (stack.getTagCompound().hasKey("gemColor"))
+ return stack.getTagCompound().getInteger("gemColor");
+ }
+ }
+ }
+
return 16777215;
}
-
-}
+}
\ No newline at end of file diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java index 80dfdf1..cdcdd12 100755 --- a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java @@ -1,10 +1,7 @@ package darkknight.jewelrycraft.util;
import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Random;
+import java.util.*;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
@@ -106,10 +103,6 @@ public class JewelrycraftUtil { }
}
- private static boolean itemHasSubtypes(Object item) {
- return ((Item) item).getHasSubtypes() && FMLCommonHandler.instance().getSide() == Side.CLIENT;
- }
-
@SideOnly(Side.CLIENT)
public static void generateColors() {
@@ -180,17 +173,6 @@ public class JewelrycraftUtil { .getIcon(0, item.getItemDamage()).getIconName().equals("soul_sand");
}
- /*
- * @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];
@@ -224,8 +206,13 @@ public class JewelrycraftUtil { 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);
+ int cursePoints;
+ if (playerInfo.hasKey("cursePoints"))
+ cursePoints = (playerInfo.getInteger("cursePoints") + points);
+ else
+ cursePoints = points;
+
+ playerInfo.setInteger("cursePoints", cursePoints);
playerInfo.setBoolean("playerCursePointsChanged", true);
}
|
