net.minecraft.nbt.StringTag Java Examples
The following examples show how to use
net.minecraft.nbt.StringTag.
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: AuthorCmd.java From Wurst7 with 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 File: ListValue.java From fabric-carpet with 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 File: BlockValue.java From fabric-carpet with 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 File: NBTSerializableValue.java From fabric-carpet with 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 File: EntityValue.java From fabric-carpet with 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 File: ShapeDispatcher.java From fabric-carpet with MIT License | 4 votes |
@Override public Tag toTag(Value value) { return StringTag.of(value.getString()); }
Example #7
Source File: StringValue.java From fabric-carpet with MIT License | 4 votes |
@Override public Tag toTag(boolean force) { return StringTag.of(str); }
Example #8
Source File: NullValue.java From fabric-carpet with MIT License | 4 votes |
@Override public Tag toTag(boolean force) { if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this); return StringTag.of("null"); }
Example #9
Source File: LazyListValue.java From fabric-carpet with MIT License | 4 votes |
@Override public Tag toTag(boolean force) { if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this); return StringTag.of(getString()); }
Example #10
Source File: FormattedTextValue.java From fabric-carpet with 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 File: FunctionValue.java From fabric-carpet with MIT License | 4 votes |
@Override public Tag toTag(boolean force) { if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this); return StringTag.of(getString()); }