Java Code Examples for net.minecraft.nbt.StringTag
The following examples show how to use
net.minecraft.nbt.StringTag. These examples are extracted from open source projects.
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 Project: Wurst7 Source File: AuthorCmd.java License: GNU General Public License v3.0 | 6 votes |
@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)); }
Example 2
Source Project: fabric-carpet Source File: ListValue.java License: MIT License | 5 votes |
@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 3
Source Project: fabric-carpet Source File: BlockValue.java License: MIT License | 5 votes |
@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; }
Example 4
Source Project: fabric-carpet Source File: NBTSerializableValue.java License: MIT License | 5 votes |
@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; }
Example 5
Source Project: fabric-carpet Source File: EntityValue.java License: MIT License | 5 votes |
@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; }
Example 6
Source Project: fabric-carpet Source File: ShapeDispatcher.java License: MIT License | 4 votes |
@Override public Tag toTag(Value value) { return StringTag.of(value.getString()); }
Example 7
Source Project: fabric-carpet Source File: StringValue.java License: MIT License | 4 votes |
@Override public Tag toTag(boolean force) { return StringTag.of(str); }
Example 8
Source Project: fabric-carpet Source File: NullValue.java License: MIT License | 4 votes |
@Override public Tag toTag(boolean force) { if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this); return StringTag.of("null"); }
Example 9
Source Project: fabric-carpet Source File: LazyListValue.java License: MIT License | 4 votes |
@Override public Tag toTag(boolean force) { if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this); return StringTag.of(getString()); }
Example 10
Source Project: fabric-carpet Source File: FormattedTextValue.java License: MIT License | 4 votes |
@Override public Tag toTag(boolean force) { if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this); return StringTag.of(Text.Serializer.toJson(text)); }
Example 11
Source Project: fabric-carpet Source File: FunctionValue.java License: MIT License | 4 votes |
@Override public Tag toTag(boolean force) { if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this); return StringTag.of(getString()); }