net.minecraft.nbt.ListTag Java Examples

The following examples show how to use net.minecraft.nbt.ListTag. 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: ItemContentUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public static List<ItemStack> getItemsInContainer(ItemStack item) {
	List<ItemStack> items = new ArrayList<>(Collections.nCopies(27, new ItemStack(Items.AIR)));
	CompoundTag nbt = item.getTag();
	
	if (nbt != null && nbt.contains("BlockEntityTag")) {
		CompoundTag nbt2 = nbt.getCompound("BlockEntityTag");
		if (nbt2.contains("Items")) {
			ListTag nbt3 = (ListTag) nbt2.get("Items");
			for (int i = 0; i < nbt3.size(); i++) {
				items.set(nbt3.getCompound(i).getByte("Slot"), ItemStack.fromTag(nbt3.getCompound(i)));
			}
		}
	}
	
	return items;
}
 
Example #2
Source File: ItemContentUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public static List<ItemStack> getItemsInContainer(ItemStack item) {
	List<ItemStack> items = new ArrayList<>(Collections.nCopies(27, new ItemStack(Items.AIR)));
	CompoundTag nbt = item.getTag();
	
	if (nbt != null && nbt.containsKey("BlockEntityTag")) {
		CompoundTag nbt2 = nbt.getCompound("BlockEntityTag");
		if (nbt2.containsKey("Items")) {
			ListTag nbt3 = (ListTag) nbt2.getTag("Items");
			for (int i = 0; i < nbt3.size(); i++) {
				items.set(nbt3.getCompoundTag(i).getByte("Slot"), ItemStack.fromTag(nbt3.getCompoundTag(i)));
			}
		}
	}
	
	return items;
}
 
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: ItemContentUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public static List<ItemStack> getItemsInContainer(ItemStack item) {
	List<ItemStack> items = new ArrayList<>(Collections.nCopies(27, new ItemStack(Items.AIR)));
	CompoundTag nbt = item.getTag();
	
	if (nbt != null && nbt.contains("BlockEntityTag")) {
		CompoundTag nbt2 = nbt.getCompound("BlockEntityTag");
		if (nbt2.contains("Items")) {
			ListTag nbt3 = (ListTag) nbt2.get("Items");
			for (int i = 0; i < nbt3.size(); i++) {
				items.set(nbt3.getCompound(i).getByte("Slot"), ItemStack.fromTag(nbt3.getCompound(i)));
			}
		}
	}
	
	return items;
}
 
Example #5
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 #6
Source File: MixinEnchantedBookItem.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public String getCreatorModId(ItemStack itemStack) {
	final Item item = itemStack.getItem();
	final Identifier defaultId = Registry.ITEM.getDefaultId();
	final Identifier id = Registry.ITEM.getId(item);

	if (defaultId.equals(id) && item != Registry.ITEM.get(defaultId)) {
		return null;
	} else {
		final String namespace = id.getNamespace();

		if ("minecraft".equals(namespace)) {
			final ListTag enchantments = EnchantedBookItem.getEnchantmentTag(itemStack);

			if (enchantments.size() == 1) {
				final Identifier enchantmentId = Identifier.tryParse(enchantments.getCompound(0).getString("id"));

				if (Registry.ENCHANTMENT.getOrEmpty(enchantmentId).isPresent()) {
					return enchantmentId.getNamespace();
				}
			}
		}

		return namespace;
	}
}
 
Example #7
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 #8
Source File: ItemContentUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static List<List<String>> getTextInBook(ItemStack item) {
	List<String> pages = new ArrayList<>();
	CompoundTag nbt = item.getTag();
	
	if (nbt != null && nbt.contains("pages")) {
		ListTag nbt2 = nbt.getList("pages", 8);
		for (int i = 0; i < nbt2.size(); i++) pages.add(nbt2.getString(i));
	}
	
	List<List<String>> finalPages = new ArrayList<>();
	
	for (String s: pages) {
		String buffer = "";
		List<String> pageBuffer = new ArrayList<>();
		
		for (char c: s.toCharArray()) {
			if (MinecraftClient.getInstance().textRenderer.getWidth(buffer) > 114 || buffer.endsWith("\n")) {
				pageBuffer.add(buffer.replace("\n", ""));
				buffer = "";
			}
			
			buffer += c;
		}
		pageBuffer.add(buffer);
		finalPages.add(pageBuffer);
	}
	
	return finalPages;
}
 
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: ItemContentUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static List<List<String>> getTextInBook(ItemStack item) {
	List<String> pages = new ArrayList<>();
	CompoundTag nbt = item.getTag();
	
	if (nbt != null && nbt.contains("pages")) {
		ListTag nbt2 = nbt.getList("pages", 8);
		for (int i = 0; i < nbt2.size(); i++) pages.add(nbt2.getString(i));
	}
	
	List<List<String>> finalPages = new ArrayList<>();
	
	for (String s: pages) {
		String buffer = "";
		List<String> pageBuffer = new ArrayList<>();
		
		for (char c: s.toCharArray()) {
			if (MinecraftClient.getInstance().textRenderer.getStringWidth(buffer) > 114 || buffer.endsWith("\n")) {
				pageBuffer.add(buffer.replace("\n", ""));
				buffer = "";
			}
			
			buffer += c;
		}
		pageBuffer.add(buffer);
		finalPages.add(pageBuffer);
	}
	
	return finalPages;
}
 
Example #11
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 #12
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 5 votes vote down vote up
public Value decode(Tag tag)
{
    ListTag ctag = (ListTag)tag;
    return ListValue.of(
            new NumericValue(ctag.getDouble(0)),
            new NumericValue(ctag.getDouble(1)),
            new NumericValue(ctag.getDouble(2))
    );
}
 
Example #13
Source File: ItemContentUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static List<List<String>> getTextInBook(ItemStack item) {
	List<String> pages = new ArrayList<>();
	CompoundTag nbt = item.getTag();
	
	if (nbt != null && nbt.containsKey("pages")) {
		ListTag nbt2 = nbt.getList("pages", 8);
		for (int i = 0; i < nbt2.size(); i++) pages.add(nbt2.getString(i));
	}
	
	List<List<String>> finalPages = new ArrayList<>();
	
	for (String s: pages) {
		String buffer = "";
		List<String> pageBuffer = new ArrayList<>();
		
		for (char c: s.toCharArray()) {
			if (MinecraftClient.getInstance().textRenderer.getStringWidth(buffer) > 114 || buffer.endsWith("\n")) {
				pageBuffer.add(buffer.replace("\n", ""));
				buffer = "";
			}
			
			buffer += c;
		}
		pageBuffer.add(buffer);
		finalPages.add(pageBuffer);
	}
	
	return finalPages;
}
 
Example #14
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 5 votes vote down vote up
public Value decode(Tag tag)
{
    ListTag ltag = (ListTag)tag;
    List<Value> points = new ArrayList<>();
    for (int i=0, ll = ltag.size(); i<ll; i++)
    {
        ListTag ptag = ltag.getList(i);
        points.add(ListValue.of(
                new NumericValue(ptag.getDouble(0)),
                new NumericValue(ptag.getDouble(1)),
                new NumericValue(ptag.getDouble(2))
        ));
    }
    return ListValue.wrap(points);
}
 
Example #15
Source File: ShapesRenderer.java    From fabric-carpet with MIT License 5 votes vote down vote up
public void addShapes(ListTag tag)
{
    for (int i=0, count = tag.size(); i < count; i++)
    {
        addShape(tag.getCompound(i));
    }
}
 
Example #16
Source File: ListValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static TagTypeCompat getType(Tag tag)
{
    if (tag instanceof IntTag) return INT;
    if (tag instanceof LongTag) return LONG;
    if (tag instanceof DoubleTag) return DBL;
    if (tag instanceof ListTag) return LIST;
    if (tag instanceof CompoundTag) return MAP;
    return STRING;
}
 
Example #17
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;
}
 
Example #18
Source File: NBTSerializableValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, Tag newElement, Tag currentTag)
{
    Collection<Tag> targets;
    try
    {
        targets = nbtPath.getOrInit(currentTag, ListTag::new);
    }
    catch (CommandSyntaxException e)
    {
        return false;
    }

    boolean modified = false;
    for (Tag target : targets)
    {
        if (!(target instanceof AbstractListTag))
        {
            continue;
        }
        try
        {
            AbstractListTag<?> targetList = (AbstractListTag) target;
            if (!targetList.addTag(index < 0 ? targetList.size() + index + 1 : index, newElement.copy()))
                return false;
            modified = true;
        }
        catch (IndexOutOfBoundsException ignored)
        {
        }
    }
    return modified;
}
 
Example #19
Source File: CarpetClient.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void onClientCommand(Tag t)
{
    CarpetSettings.LOG.info("Server Response:");
    CompoundTag tag = (CompoundTag)t;
    CarpetSettings.LOG.info(" - id: "+tag.getString("id"));
    CarpetSettings.LOG.info(" - code: "+tag.getInt("code"));
    if (tag.contains("error")) CarpetSettings.LOG.warn(" - error: "+tag.getString("error"));
    if (tag.contains("output"))
    {
        ListTag outputTag = (ListTag) tag.get("output");
        for (int i = 0; i < outputTag.size(); i++)
            CarpetSettings.LOG.info(" - response: " + Text.Serializer.fromJson(outputTag.getString(i)).getString());
    }
}
 
Example #20
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 #21
Source File: CandyComponent.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void fromTag(CompoundTag tag) {
	ListTag list = tag.getList("entities", 10);
	for (int i = 0; i < list.size(); i++) {
		CompoundTag item = list.getCompound(i);
		lastGivenCandy.put(item.getUuid("uuid"), item.getLong("time"));
	}
}
 
Example #22
Source File: MixinCompoundTag.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
public <T> List<T> sbx$getList(String key, Class<T> tagType) {
    int id = 0;
    if (tagType == org.sandboxpowered.sandbox.api.util.nbt.CompoundTag.class) {
        id = 10;
    }
    //TODO
    ListTag tag = getList(key, id);
    return (List<T>) tag;
}
 
Example #23
Source File: EntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(
        method = "fromTag",
        at = @At(value = "INVOKE", shift = At.Shift.AFTER,
                target = "Lnet/minecraft/entity/Entity;readCustomDataFromTag(Lnet/minecraft/nbt/CompoundTag;)V")
)
private void onFromTag(CompoundTag compoundTag_1, CallbackInfo ci)
{
    if (this.shouldSetPositionOnLoad())
    {
        this.refreshPosition();
    }
    
    if (CarpetExtraSettings.reloadSuffocationFix && compoundTag_1.contains("CM_Box", 9))
    {
        ListTag box_tag = compoundTag_1.getList("CM_Box", 6);
        
        Box box = new Box(box_tag.getDouble(0), box_tag.getDouble(1),
                box_tag.getDouble(2), box_tag.getDouble(3),
                box_tag.getDouble(4), box_tag.getDouble(5));

        double deltaX = ((box.x1 + box.x2) / 2.0D) - this.x;
        double deltaY = box.y1 - this.y;
        double deltaZ = ((box.z1 + box.z2) / 2.0D) - this.z;
        
        // Credits: MrGrim (MUP) -> Sanity check.
        // If the position and BoundingBox center point are > 0.1 blocks apart then do not restore the BoundingBox. In vanilla
        // this should never happen, but mods might not be aware that the BoundingBox is stored and that the entity
        // position will be reset to it.
        if (((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ)) < 0.01D)
        {
            this.setBoundingBox(box);
        }
    }
}
 
Example #24
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 #25
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 #26
Source File: Items_1_12_2.java    From multiconnect with MIT License 5 votes vote down vote up
private static void oldEnchantmentListToNew(ListTag enchantments) {
    for (int i = 0; i < enchantments.size(); i++) {
        CompoundTag ench = enchantments.getCompound(i);
        int id = ench.getInt("id");
        Identifier name = Registry.ENCHANTMENT.getId(Registry.ENCHANTMENT.get(id));
        if (name == null) {
            enchantments.remove(i);
            i--;
        } else {
            ench.putString("id", name.toString());
        }
    }
}
 
Example #27
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 #28
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 #29
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 #30
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);
}