Java源码示例:net.minecraft.nbt.StringTag

示例1
@Override
public void call(String[] args) throws CmdException
{
	if(args.length == 0)
		throw new CmdSyntaxError();
	
	if(!MC.player.abilities.creativeMode)
		throw new CmdError("Creative mode only.");
	
	ItemStack heldItem = MC.player.inventory.getMainHandStack();
	int heldItemID = Item.getRawId(heldItem.getItem());
	int writtenBookID = Item.getRawId(Items.WRITTEN_BOOK);
	
	if(heldItemID != writtenBookID)
		throw new CmdError(
			"You must hold a written book in your main hand.");
	
	String author = String.join(" ", args);
	heldItem.putSubTag("author", StringTag.of(author));
}
 
示例2
@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;
}
 
示例3
@Override
public Tag toTag(boolean force)
{
    if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
    // follows falling block convertion
    CompoundTag tag =  new CompoundTag();
    CompoundTag state = new CompoundTag();
    BlockState s = getBlockState();
    state.put("Name", StringTag.of(Registry.BLOCK.getId(s.getBlock()).toString()));
    Collection<Property<?>> properties = s.getProperties();
    if (!properties.isEmpty())
    {
        CompoundTag props = new CompoundTag();
        for (Property<?> p: properties)
        {
            props.put(p.getName(), StringTag.of(s.get(p).toString().toLowerCase(Locale.ROOT)));
        }
        state.put("Properties", props);
    }
    tag.put("BlockState", state);
    CompoundTag dataTag = getData();
    if (dataTag != null)
    {
        tag.put("TileEntityData", dataTag);
    }
    return tag;
}
 
示例4
@Override
public boolean getBoolean()
{
    Tag tag = getTag();
    if (tag instanceof CompoundTag)
        return !((CompoundTag) tag).isEmpty();
    if (tag instanceof AbstractListTag)
        return ((AbstractListTag) tag).isEmpty();
    if (tag instanceof AbstractNumberTag)
        return ((AbstractNumberTag) tag).getDouble()!=0.0;
    if (tag instanceof StringTag)
        return tag.asString().isEmpty();
    return true;
}
 
示例5
@Override
public Tag toTag(boolean force)
{
    if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
    CompoundTag tag = new CompoundTag();
    tag.put("Data", getEntity().toTag( new CompoundTag()));
    tag.put("Name", StringTag.of(Registry.ENTITY_TYPE.getId(entity.getType()).toString()));
    return tag;
}
 
示例6
@Override
public Tag toTag(Value value) { return StringTag.of(value.getString()); }
 
示例7
@Override
public Tag toTag(boolean force)
{
    return StringTag.of(str);
}
 
示例8
@Override
public Tag toTag(boolean force)
{
    if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
    return StringTag.of("null");
}
 
示例9
@Override
public Tag toTag(boolean force)
{
    if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
    return StringTag.of(getString());
}
 
示例10
@Override
public Tag toTag(boolean force)
{
    if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
    return StringTag.of(Text.Serializer.toJson(text));
}
 
示例11
@Override
public Tag toTag(boolean force)
{
    if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
    return StringTag.of(getString());
}