mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 11:19:19 +00:00
Minor clean up ItemNBTHelper
This commit is contained in:
5 files changed
+6
-24
No files matched your search
@@ -21,7 +21,7 @@ public final class TooltipHandler {
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public static void onTooltipEvent(ItemTooltipEvent event) {
|
||||
if(ItemNBTHelper.detectNBT(event.getItemStack()) && ItemNBTHelper.getBoolean(event.getItemStack(), ItemKeepIvy.TAG_KEEP, false))
|
||||
if(event.getItemStack().hasTagCompound() && ItemNBTHelper.getBoolean(event.getItemStack(), ItemKeepIvy.TAG_KEEP, false))
|
||||
event.getToolTip().add(I18n.format("botaniamisc.hasKeepIvy"));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,29 +21,11 @@ public final class ItemNBTHelper {
|
||||
|
||||
private static final int[] EMPTY_INT_ARRAY = new int[0];
|
||||
|
||||
/** Checks if an ItemStack has a Tag Compound **/
|
||||
public static boolean detectNBT(ItemStack stack) {
|
||||
return stack.hasTagCompound();
|
||||
}
|
||||
|
||||
/** Tries to initialize an NBT Tag Compound in an ItemStack,
|
||||
* this will not do anything if the stack already has a tag
|
||||
* compound **/
|
||||
public static void initNBT(ItemStack stack) {
|
||||
if(!detectNBT(stack))
|
||||
injectNBT(stack, new NBTTagCompound());
|
||||
}
|
||||
|
||||
/** Injects an NBT Tag Compound to an ItemStack, no checks
|
||||
* are made previously **/
|
||||
public static void injectNBT(ItemStack stack, NBTTagCompound nbt) {
|
||||
stack.setTagCompound(nbt);
|
||||
}
|
||||
|
||||
/** Gets the NBTTagCompound in an ItemStack. Tries to init it
|
||||
* previously in case there isn't one present **/
|
||||
public static NBTTagCompound getNBT(ItemStack stack) {
|
||||
initNBT(stack);
|
||||
if(!stack.hasTagCompound())
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
return stack.getTagCompound();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class KeepIvyRecipe implements IRecipe {
|
||||
if(!stack.isEmpty()) {
|
||||
if(stack.getItem() == ModItems.keepIvy)
|
||||
foundIvy = true;
|
||||
else if(!foundItem && !(ItemNBTHelper.detectNBT(stack) && ItemNBTHelper.getBoolean(stack, ItemKeepIvy.TAG_KEEP, false)) && !stack.getItem().hasContainerItem(stack))
|
||||
else if(!foundItem && !(stack.hasTagCompound() && ItemNBTHelper.getBoolean(stack, ItemKeepIvy.TAG_KEEP, false)) && !stack.getItem().hasContainerItem(stack))
|
||||
foundItem = true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ItemKeepIvy extends ItemMod {
|
||||
List<EntityItem> keeps = new ArrayList<>();
|
||||
for(EntityItem item : event.getDrops()) {
|
||||
ItemStack stack = item.getEntityItem();
|
||||
if(!stack.isEmpty() && ItemNBTHelper.detectNBT(stack) && ItemNBTHelper.getBoolean(stack, TAG_KEEP, false))
|
||||
if(!stack.isEmpty() && stack.hasTagCompound() && ItemNBTHelper.getBoolean(stack, TAG_KEEP, false))
|
||||
keeps.add(item);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ItemBlockSpecialFlower extends ItemBlockMod implements IRecipeKeyPr
|
||||
}
|
||||
|
||||
public static String getType(ItemStack stack) {
|
||||
return ItemNBTHelper.detectNBT(stack) ? ItemNBTHelper.getString(stack, SubTileEntity.TAG_TYPE, "") : "";
|
||||
return stack.hasTagCompound() ? ItemNBTHelper.getString(stack, SubTileEntity.TAG_TYPE, "") : "";
|
||||
}
|
||||
|
||||
public static ItemStack ofType(String type) {
|
||||
|
||||
Reference in new issue
Block a user