Java Code Examples for net.minecraft.nbt.CompoundTag#putInt()

The following examples show how to use net.minecraft.nbt.CompoundTag#putInt() . 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: HallowCharmItem.java    From the-hallow with MIT License 7 votes vote down vote up
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
	PlayerEntity player = context.getPlayer();
	if (context.getWorld().isClient) return ActionResult.PASS;
	BlockState state = context.getWorld().getBlockState(context.getBlockPos());
	if(state.getBlock() == HallowedBlocks.HALLOWED_GATE) {
		if (context.getWorld().getDimension().getType() == DimensionType.OVERWORLD) {
			if (HallowedGateBlock.isValid(context.getWorld(), context.getBlockPos(), state)) {
				BlockPos pos = player.getBlockPos();
				CompoundTag tag = new CompoundTag();
				tag.putInt("x", pos.getX());
				tag.putInt("y", pos.getY());
				tag.putInt("z", pos.getZ());
				context.getStack().putSubTag("PortalLoc", tag);
				FabricDimensions.teleport(player, HallowedDimensions.THE_HALLOW);
				return ActionResult.SUCCESS;
			} else {
				player.addChatMessage(new TranslatableText("text.thehallow.gate_incomplete"), true);
			}
		} else {
			player.addChatMessage(new TranslatableText("text.thehallow.gate_in_wrong_dimension"), true);
		}
	}
	return ActionResult.PASS;
}
 
Example 2
Source File: HallowedTreasureChestEntity.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
protected void writeCustomDataToTag(CompoundTag compoundTag) {
	compoundTag.putBoolean("shouldReplace", shouldReplace);
	compoundTag.putBoolean("hasReplaced", hasReplaced);
	
	compoundTag.putInt("spinProgress", spinProgress);
	compoundTag.putInt("endProgress", endProgress);
	compoundTag.putInt("hingeProgress", hingeProgress);
	
	compoundTag.putBoolean("isSpinningUp", isSpinningUp);
	compoundTag.putBoolean("isEnding", isEnding);
	compoundTag.putBoolean("isOpeningHinge", isOpeningHinge);
	
	compoundTag.putFloat("rotation", rotation);
	compoundTag.putFloat("previousRotation", previousRotation);
}
 
Example 3
Source File: PotionCmd.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private ListTag convertEffectsToNbt(ItemStack stack)
{
	ListTag nbt = new ListTag();
	List<StatusEffectInstance> effects =
		PotionUtil.getCustomPotionEffects(stack);
	
	for(StatusEffectInstance effect : effects)
	{
		CompoundTag tag = new CompoundTag();
		
		int id = StatusEffect.getRawId(effect.getEffectType());
		tag.putInt("Id", id);
		tag.putInt("Amplifier", effect.getAmplifier());
		tag.putInt("Duration", effect.getDuration());
		
		nbt.add(tag);
	}
	
	return nbt;
}
 
Example 4
Source File: KillPotionHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable()
{
	// check gamemode
	if(!MC.player.abilities.creativeMode)
	{
		ChatUtils.error("Creative mode only.");
		setEnabled(false);
		return;
	}
	
	// generate potion
	ItemStack stack = new ItemStack(Items.SPLASH_POTION);
	CompoundTag effect = new CompoundTag();
	effect.putInt("Amplifier", 125);
	effect.putInt("Duration", 2000);
	effect.putInt("Id", 6);
	ListTag effects = new ListTag();
	effects.add(effect);
	CompoundTag nbt = new CompoundTag();
	nbt.put("CustomPotionEffects", effects);
	stack.setTag(nbt);
	String name = "\u00a7rSplash Potion of \u00a74\u00a7lINSTANT DEATH";
	stack.setCustomName(new LiteralText(name));
	
	// give potion
	if(placeStackInHotbar(stack))
		ChatUtils.message("Potion created.");
	else
		ChatUtils.error("Please clear a slot in your hotbar.");
	
	setEnabled(false);
}
 
Example 5
Source File: CmdEnchant.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void enchant(ItemStack item, Enchantment e, int level) {
	if (item.getTag() == null) item.setTag(new CompoundTag());
	if (!item.getTag().contains("Enchantments", 9)) {
		item.getTag().put("Enchantments", new ListTag());
    }

    ListTag listnbt = item.getTag().getList("Enchantments", 10);
    CompoundTag compoundnbt = new CompoundTag();
    compoundnbt.putString("id", String.valueOf(Registry.ENCHANTMENT.getId(e)));
    compoundnbt.putInt("lvl", level);
    listnbt.add(compoundnbt);
}
 
Example 6
Source File: CmdEnchant.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void enchant(ItemStack item, Enchantment e, int level) {
	if (item.getTag() == null) item.setTag(new CompoundTag());
	if (!item.getTag().contains("Enchantments", 9)) {
		item.getTag().put("Enchantments", new ListTag());
    }

    ListTag listnbt = item.getTag().getList("Enchantments", 10);
    CompoundTag compoundnbt = new CompoundTag();
    compoundnbt.putString("id", String.valueOf(Registry.ENCHANTMENT.getId(e)));
    compoundnbt.putInt("lvl", level);
    listnbt.add(compoundnbt);
}
 
Example 7
Source File: CmdEnchant.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void enchant(ItemStack item, Enchantment e, int level) {
	if (item.getTag() == null) item.setTag(new CompoundTag());
	if (!item.getTag().containsKey("Enchantments", 9)) {
		item.getTag().put("Enchantments", new ListTag());
    }

    ListTag listnbt = item.getTag().getList("Enchantments", 10);
    CompoundTag compoundnbt = new CompoundTag();
    compoundnbt.putString("id", String.valueOf(Registry.ENCHANTMENT.getId(e)));
    compoundnbt.putInt("lvl", level);
    listnbt.add(compoundnbt);
}
 
Example 8
Source File: MixinBannerBlockEntity.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "fromTag", at = @At("RETURN"))
private void onFromTag(BlockState blockState, CompoundTag tag, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        for (Tag t : patternListTag) {
            if (t instanceof CompoundTag) {
                CompoundTag pattern = (CompoundTag) t;
                pattern.putInt("Color", 15 - pattern.getInt("Color"));
            }
        }
    }
}
 
Example 9
Source File: Items_1_12_2.java    From multiconnect with MIT License 5 votes vote down vote up
private static ItemStack invertBannerColors(ItemStack stack) {
    stack = stack.copy();
    CompoundTag blockEntityTag = stack.getSubTag("BlockEntityTag");
    if (blockEntityTag != null && blockEntityTag.contains("Patterns", 9)) {
        ListTag patterns = blockEntityTag.getList("Patterns", 10);
        for (Tag t : patterns) {
            CompoundTag pattern = (CompoundTag) t;
            if (pattern.contains("Color", 3))
                pattern.putInt("Color", 15 - pattern.getInt("Color"));
        }
    }
    return stack;
}
 
Example 10
Source File: Items_1_12_2.java    From multiconnect with MIT License 5 votes vote down vote up
private static void newEnchantmentListToOld(ListTag enchantments) {
    for (int i = 0; i < enchantments.size(); i++) {
        CompoundTag ench = enchantments.getCompound(i);
        Identifier name = Identifier.tryParse(ench.getString("id"));
        Enchantment enchObj = Registry.ENCHANTMENT.get(name);
        if (enchObj == null) {
            enchantments.remove(i);
            i--;
        } else {
            ench.putInt("id", Registry.ENCHANTMENT.getRawId(enchObj));
        }
    }
}
 
Example 11
Source File: PotionCmd.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private void remove(ItemStack stack, String[] args) throws CmdSyntaxError
{
	if(args.length != 2)
		throw new CmdSyntaxError();
	
	int id = parseEffectId(args[1]);
	
	List<StatusEffectInstance> oldEffects =
		PotionUtil.getCustomPotionEffects(stack);
	
	ListTag newEffects = new ListTag();
	for(StatusEffectInstance oldEffect : oldEffects)
	{
		int oldId = StatusEffect.getRawId(oldEffect.getEffectType());
		
		if(oldId == id)
			continue;
		
		CompoundTag effect = new CompoundTag();
		effect.putInt("Id", oldId);
		effect.putInt("Amplifier", oldEffect.getAmplifier());
		effect.putInt("Duration", oldEffect.getDuration());
		newEffects.add(effect);
	}
	
	CompoundTag nbt = new CompoundTag();
	nbt.put("CustomPotionEffects", newEffects);
	stack.setTag(nbt);
	ChatUtils.message("Effect removed.");
}
 
Example 12
Source File: TrollPotionHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable()
{
	// check gamemode
	if(!MC.player.abilities.creativeMode)
	{
		ChatUtils.error("Creative mode only.");
		setEnabled(false);
		return;
	}
	
	// generate potion
	ItemStack stack = new ItemStack(Items.SPLASH_POTION);
	ListTag effects = new ListTag();
	for(int i = 1; i <= 23; i++)
	{
		CompoundTag effect = new CompoundTag();
		effect.putInt("Amplifier", Integer.MAX_VALUE);
		effect.putInt("Duration", Integer.MAX_VALUE);
		effect.putInt("Id", i);
		effects.add(effect);
	}
	CompoundTag nbt = new CompoundTag();
	nbt.put("CustomPotionEffects", effects);
	stack.setTag(nbt);
	String name = "\u00a7rSplash Potion of Trolling";
	stack.setCustomName(new LiteralText(name));
	
	// give potion
	if(placeStackInHotbar(stack))
		ChatUtils.message("Potion created.");
	else
		ChatUtils.error("Please clear a slot in your hotbar.");
	
	setEnabled(false);
}
 
Example 13
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 14
Source File: ElectricCompressorBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public CompoundTag toTag(CompoundTag tag) {
    super.toTag(tag);
    tag.putInt("Energy", getCapacitatorComponent().getCurrentEnergy());

    return tag;
}
 
Example 15
Source File: BasicSolarPanelPartBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public CompoundTag toTag(CompoundTag tag) {
    tag = super.toTag(tag);
    CompoundTag baseTag = new CompoundTag();
    baseTag.putInt("X", this.basePos.getX());
    baseTag.putInt("Y", this.basePos.getY());
    baseTag.putInt("Z", this.basePos.getZ());

    tag.put("Base", baseTag);
    return tag;
}
 
Example 16
Source File: CircuitFabricatorBlockEntity.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public CompoundTag toTag(CompoundTag tag) {
    super.toTag(tag);
    tag.putInt("Progress", this.progress);
    return tag;
}
 
Example 17
Source File: RestlessCactusEntity.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public void writeCustomDataToTag(CompoundTag tag) {
	super.writeCustomDataToTag(tag);
	tag.putInt("CactusHeight", getCactusHeight());
	tag.putInt("CactusAge", age);
}
 
Example 18
Source File: CompressorBlockEntity.java    From Galacticraft-Rewoven with MIT License 3 votes vote down vote up
@Override
public CompoundTag toTag(CompoundTag tag) {
    super.toTag(tag);

    tag.putInt("Progress", this.progress);

    tag.putInt("FuelTime", this.fuelTime);

    return tag;
}