Java Code Examples for net.minecraft.item.ItemStack#hasTag()
The following examples show how to use
net.minecraft.item.ItemStack#hasTag() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModifyCmd.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private void add(ItemStack stack, String[] args) throws CmdError { String nbt = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); nbt = nbt.replace("$", "\u00a7").replace("\u00a7\u00a7", "$"); if(!stack.hasTag()) stack.setTag(new CompoundTag()); try { CompoundTag tag = StringNbtReader.parse(nbt); stack.getTag().copyFrom(tag); }catch(CommandSyntaxException e) { ChatUtils.message(e.getMessage()); throw new CmdError("NBT data is invalid."); } }
Example 2
Source File: GalacticraftEnergy.java From Galacticraft-Rewoven with MIT License | 5 votes |
public static boolean isOxygenItem(ItemStack itemStack) { if (!itemStack.hasTag()) { return false; } CompoundTag tag = itemStack.getTag() == null ? new CompoundTag() : itemStack.getTag(); return tag.contains(OxygenTankItem.OXYGEN_NBT_KEY) && tag.contains(OxygenTankItem.MAX_OXYGEN_NBT_KEY); }
Example 3
Source File: NBTSerializableValue.java From fabric-carpet with MIT License | 5 votes |
public static Value fromStack(ItemStack stack) { if (stack.hasTag()) { NBTSerializableValue value = new NBTSerializableValue(); value.nbtSupplier = stack::getTag; return value; } return Value.NULL; }
Example 4
Source File: ItemEntityMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject( method = "tryMerge(Lnet/minecraft/entity/ItemEntity;)V", at = @At("HEAD"), cancellable = true ) private void tryStackShulkerBoxes(ItemEntity other, CallbackInfo ci) { ItemEntity self = (ItemEntity)(Object)this; ItemStack selfStack = self.getStack(); if (!CarpetSettings.stackableShulkerBoxes || !(selfStack.getItem() instanceof BlockItem) || !(((BlockItem)selfStack.getItem()).getBlock() instanceof ShulkerBoxBlock)) { return; } ItemStack otherStack = other.getStack(); if (selfStack.getItem() == otherStack.getItem() && !InventoryHelper.shulkerBoxHasItems(selfStack) && !InventoryHelper.shulkerBoxHasItems(otherStack) && selfStack.hasTag() == otherStack.hasTag() && selfStack.getCount() + otherStack.getCount() <= SHULKERBOX_MAX_STACK_AMOUNT) { int amount = Math.min(otherStack.getCount(), SHULKERBOX_MAX_STACK_AMOUNT - selfStack.getCount()); selfStack.increment(amount); self.setStack(selfStack); this.pickupDelay = Math.max(((ItemEntityInterface)other).getPickupDelayCM(), this.pickupDelay); this.age = Math.min(((ItemEntityInterface)other).getAgeCM(), this.age); otherStack.decrement(amount); if (otherStack.isEmpty()) { other.remove(); } else { other.setStack(otherStack); } ci.cancel(); } }
Example 5
Source File: Frequency.java From EnderStorage with MIT License | 5 votes |
public static Frequency readFromStack(ItemStack stack) { if (stack.hasTag()) { CompoundNBT stackTag = stack.getTag(); if (stackTag.contains("Frequency")) { return new Frequency(stackTag.getCompound("Frequency")); } } return new Frequency(); }
Example 6
Source File: EnergisedItem.java From MiningGadgets with MIT License | 4 votes |
public EnergisedItem(ItemStack stack, int capacity) { super(getMaxCapacity(stack, capacity), Integer.MAX_VALUE, Integer.MAX_VALUE); this.stack = stack; this.energy = stack.hasTag() && stack.getTag().contains("energy") ? stack.getTag().getInt("energy") : 0; }
Example 7
Source File: EnergisedItem.java From MiningGadgets with MIT License | 4 votes |
private static int getMaxCapacity(ItemStack stack, int capacity) { if( !stack.hasTag() || !stack.getTag().contains("max_energy") ) return capacity; return stack.getTag().getInt("max_energy"); }
Example 8
Source File: IForgeItem.java From patchwork-api with GNU Lesser General Public License v2.1 | 2 votes |
/** * Return the itemDamage represented by this ItemStack. Defaults to the Damage * entry in the stack NBT, but can be overridden here for other sources. * * @param stack The itemstack that is damaged * @return the damage value */ default int getDamage(ItemStack stack) { return !stack.hasTag() ? 0 : stack.getTag().getInt("Damage"); }