Java Code Examples for net.minecraft.item.ItemStack#getOrCreateTag()

The following examples show how to use net.minecraft.item.ItemStack#getOrCreateTag() . 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: UpgradeTools.java    From MiningGadgets with MIT License 6 votes vote down vote up
public static void updateUpgrade(ItemStack tool, Upgrade upgrade) {
    CompoundNBT tagCompound = tool.getOrCreateTag();
    ListNBT list = tagCompound.getList(KEY_UPGRADES, Constants.NBT.TAG_COMPOUND);

    list.forEach( e -> {
        CompoundNBT compound = (CompoundNBT) e;
        String name = compound.getString(KEY_UPGRADE);
        boolean enabled = compound.getBoolean(KEY_ENABLED);

        if( (name.contains(Upgrade.FORTUNE_1.getBaseName()) && enabled && upgrade.lazyIs(Upgrade.SILK) )
                        || (name.equals(Upgrade.SILK.getBaseName()) && enabled && upgrade.lazyIs(Upgrade.FORTUNE_1) ))
            compound.putBoolean(KEY_ENABLED, false);

        if( name.equals(upgrade.getName()) )
            compound.putBoolean(KEY_ENABLED, !compound.getBoolean(KEY_ENABLED));
    });
}
 
Example 2
Source File: GoldenCandyCornItem.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
	if (entity instanceof PlayerEntity) {
		PlayerEntity player = (PlayerEntity) entity;
		CompoundTag tag = stack.getOrCreateTag();
		if ((selected || slot == 40) && player.getHungerManager().isNotFull()) {
			if (!player.getItemCooldownManager().isCoolingDown(this) && tag.getBoolean("Eating")) {
				player.eatFood(world, stack);
				player.getItemCooldownManager().set(this, 40);
			}
		} else {
			if (tag.getBoolean("Eating")) tag.putBoolean("Eating", false);
		}
	}
}
 
Example 3
Source File: MiningProperties.java    From MiningGadgets with MIT License 5 votes vote down vote up
public static short getColor(ItemStack gadget, String color) {
    CompoundNBT compound = gadget.getOrCreateTag();
    if (color.equals(COLOR_RED) || color.contains("Inner")) {
        return !compound.contains(color) ? setColor(gadget, (short) 255, color) : compound.getShort(color);
    } else {
        return !compound.contains(color) ? setColor(gadget, (short) 0, color) : compound.getShort(color);
    }
}
 
Example 4
Source File: MiningProperties.java    From MiningGadgets with MIT License 5 votes vote down vote up
public static void nextBreakType(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    if (compound.contains(BREAK_TYPE)) {
        int type = getBreakType(gadget).ordinal() == BreakTypes.values().length - 1 ? 0 : getBreakType(gadget).ordinal() + 1;
        setBreakType(gadget, BreakTypes.values()[type]);
    } else {
        setBreakType(gadget, BreakTypes.FADE);
    }
}
 
Example 5
Source File: OxygenTankItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private ItemStack applyDefaultTags(ItemStack item, int currentOxy) {
    CompoundTag tag = item.getOrCreateTag();
    tag.putInt(MAX_OXYGEN_NBT_KEY, this.maxOxygen);
    tag.putInt(OXYGEN_NBT_KEY, currentOxy);
    item.setDamage(getMaxDamage() - currentOxy);

    return item;
}
 
Example 6
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static BreakTypes getBreakType(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(BREAK_TYPE) ? setBreakType(gadget, BreakTypes.SHRINK) : BreakTypes.values()[compound.getByte(BREAK_TYPE)];
}
 
Example 7
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static int getFreezeDelay(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(FREEZE_PARTICLE_DELAY) ? setFreezeDelay(gadget, 0) : compound.getInt(FREEZE_PARTICLE_DELAY);
}
 
Example 8
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static float getVolume(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(VOLUME) ? setVolume(gadget, 1.0f) : compound.getFloat(VOLUME);
}
 
Example 9
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static boolean getPrecisionMode(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(PRECISION_MODE) ? setPrecisionMode(gadget, false) : compound.getBoolean(PRECISION_MODE);
}
 
Example 10
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static boolean getCanMine(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(CAN_MINE) ? setCanMine(gadget, true) : compound.getBoolean(CAN_MINE);
}
 
Example 11
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static boolean getWhiteList(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(KEY_WHITELIST) ? setWhitelist(gadget, true) : compound.getBoolean(KEY_WHITELIST);
}
 
Example 12
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static int getBeamMaxRange(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(KEY_MAX_BEAM_RANGE) ? setBeamMaxRange(gadget, MIN_RANGE) : compound.getInt(KEY_MAX_BEAM_RANGE);
}
 
Example 13
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static int getBeamRange(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(KEY_BEAM_RANGE) ? setBeamRange(gadget, MIN_RANGE) : compound.getInt(KEY_BEAM_RANGE);
}
 
Example 14
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static int getRange(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(KEY_RANGE) ? setRange(gadget, 1) : compound.getInt(KEY_RANGE);
}
 
Example 15
Source File: MiningProperties.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static int getSpeed(ItemStack gadget) {
    CompoundNBT compound = gadget.getOrCreateTag();
    return !compound.contains(KEY_SPEED) ? setSpeed(gadget, 1) : compound.getInt(KEY_SPEED);
}
 
Example 16
Source File: Frequency.java    From EnderStorage with MIT License 4 votes vote down vote up
public ItemStack writeToStack(ItemStack stack) {
    CompoundNBT tagCompound = stack.getOrCreateTag();
    tagCompound.put("Frequency", write_internal(new CompoundNBT()));
    return stack;
}
 
Example 17
Source File: UpgradeTools.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static List<Upgrade> getActiveUpgrades(ItemStack tool) {
    CompoundNBT tagCompound = tool.getOrCreateTag();
    return getActiveUpgradesFromTag(tagCompound);
}
 
Example 18
Source File: UpgradeTools.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static List<Upgrade> getUpgrades(ItemStack tool) {
    CompoundNBT tagCompound = tool.getOrCreateTag();
    return getUpgradesFromTag(tagCompound);
}
 
Example 19
Source File: UpgradeTools.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static void setUpgrade(ItemStack tool, UpgradeCard upgrade) {
    CompoundNBT tagCompound = tool.getOrCreateTag();
    setUpgradeNBT(tagCompound, upgrade);
}
 
Example 20
Source File: BatteryItem.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public void onCraft(ItemStack battery, World world_1, PlayerEntity playerEntity_1) {
    CompoundTag batteryTag = battery.getOrCreateTag();
    battery.setDamage(BatteryItem.MAX_ENERGY);
    battery.setTag(batteryTag);
}