Java Code Examples for net.minecraft.nbt.ListTag#add()

The following examples show how to use net.minecraft.nbt.ListTag#add() . 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: 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 2
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public Tag toTag(Value pointsValue)
{
    List<Value> lv = ((ListValue)pointsValue).getItems();
    ListTag ltag = new ListTag();
    for (Value value : lv)
    {
        List<Value> coords = ((ListValue)value).getItems();
        ListTag tag = new ListTag();
        tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
        tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
        tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
        ltag.add(tag);
    }
    return ltag;
}
 
Example 3
Source File: CandyComponent.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public CompoundTag toTag(CompoundTag tag) {
	ListTag list = new ListTag();
	Iterator<Map.Entry<UUID, Long>> iterator = lastGivenCandy.entrySet().iterator();
	while (iterator.hasNext()) {
		Map.Entry<UUID, Long> entry = iterator.next();
		CompoundTag item = new CompoundTag();
		item.putUuid("uuid", entry.getKey());
		item.putLong("time", entry.getValue());
		list.add(item);
	}
	tag.put("entities", list);
	return tag;
}
 
Example 4
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 5
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 6
Source File: CrashChestHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable()
{
	if(!MC.player.abilities.creativeMode)
	{
		ChatUtils.error("Creative mode only.");
		setEnabled(false);
		return;
	}
	
	if(!MC.player.inventory.getArmorStack(0).isEmpty())
	{
		ChatUtils.error("Please clear your shoes slot.");
		setEnabled(false);
		return;
	}
	
	// generate item
	ItemStack stack = new ItemStack(Blocks.CHEST);
	CompoundTag nbtCompound = new CompoundTag();
	ListTag nbtList = new ListTag();
	for(int i = 0; i < 40000; i++)
		nbtList.add(new ListTag());
	nbtCompound.put("www.wurstclient.net", nbtList);
	stack.setTag(nbtCompound);
	stack.setCustomName(new LiteralText("Copy Me"));
	
	// give item
	MC.player.inventory.armor.set(0, stack);
	ChatUtils.message("Item has been placed in your shoes slot.");
	setEnabled(false);
}
 
Example 7
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 8
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 9
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 10
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 11
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public Tag toTag(Value value)
{
    List<Value> lv = ((ListValue)value).getItems();
    ListTag tag = new ListTag();
    tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
    tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
    tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
    return tag;
}
 
Example 12
Source File: ListValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public Tag toTag(boolean force)
{
    int argSize = items.size();
    if (argSize == 0) return new ListTag();
    ListTag tag = new ListTag();
    if (argSize ==1)
    {
        tag.add(items.get(0).toTag(force));
        return tag;
    }
    // figuring out the types
    List<Tag> tags= new ArrayList<>();
    items.forEach(v -> tags.add(v.toTag(force)));
    Set<TagTypeCompat> cases = EnumSet.noneOf(TagTypeCompat.class);
    tags.forEach(t -> cases.add(TagTypeCompat.getType(t)));
    if (cases.size()==1) // well, one type of items
    {
        tag.addAll(tags);
        return tag;
    }
    if (cases.contains(TagTypeCompat.LIST)
            || cases.contains(TagTypeCompat.MAP)
            || cases.contains(TagTypeCompat.STRING)) // incompatible types
    {
        if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
        tags.forEach(t -> tag.add(StringTag.of(t.asString())));
        return tag;
    }
    // only numbers / mixed types
    if (cases.contains(TagTypeCompat.DBL))
    {
        tags.forEach(t -> tag.add(DoubleTag.of(((AbstractNumberTag)t).getDouble())));
    }
    else
    {
        tags.forEach(t -> tag.add(LongTag.of(((AbstractNumberTag)t).getLong())));
    }
    return tag;
}