use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class SpongeEntitySnapshotBuilder method from.
public SpongeEntitySnapshotBuilder from(final net.minecraft.world.entity.Entity minecraftEntity) {
this.entityType = ((Entity) minecraftEntity).type();
this.worldKey = ((Entity) minecraftEntity).serverLocation().worldKey();
this.uniqueId = minecraftEntity.getUUID();
final Transform transform = ((Entity) minecraftEntity).transform();
this.position = transform.position();
this.rotation = transform.rotation();
this.scale = transform.scale();
this.manipulator = DataManipulator.mutableOf((Entity) minecraftEntity);
this.compound = new CompoundTag();
minecraftEntity.saveWithoutId(this.compound);
return this;
}
use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class BlockTypeItemStackData method set.
private static boolean set(final ItemStack stack, final String nbtKey, final Set<? extends BlockType> value) {
if (value.isEmpty()) {
stack.removeTagKey(nbtKey);
return true;
}
final CompoundTag tag = stack.getOrCreateTag();
final ListTag list = value.stream().map(type -> Registry.BLOCK.getKey((Block) type).toString()).collect(NBTCollectors.toStringTagList());
tag.put(nbtKey, list);
return true;
}
use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class CompassItemData method register.
static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ItemStack.class).create(Keys.LODESTONE).get(stack -> {
if (CompassItem.isLodestoneCompass(stack)) {
final CompoundTag tag = stack.getOrCreateTag();
final Optional<ResourceKey<Level>> dimension = CompassItem.getLodestoneDimension(tag);
if (dimension.isPresent()) {
return ServerLocation.of((ServerWorld) SpongeCommon.server().getLevel(dimension.get()), VecHelper.toVector3d(NbtUtils.readBlockPos(tag.getCompound("LodestonePos"))));
}
}
return null;
}).set((stack, location) -> {
final CompoundTag tag = stack.getOrCreateTag();
tag.put("LodestonePos", NbtUtils.writeBlockPos(VecHelper.toBlockPos(location)));
Level.RESOURCE_KEY_CODEC.encodeStart(NbtOps.INSTANCE, ((net.minecraft.server.level.ServerLevel) location.world()).dimension()).resultOrPartial(SpongeCommon.logger()::error).ifPresent(dimension -> tag.put("LodestoneDimension", dimension));
tag.putBoolean("LodestoneTracked", true);
}).delete(stack -> {
final CompoundTag tag = stack.getTag();
if (tag != null) {
tag.remove("LodestoneDimension");
tag.remove("LodestonePos");
tag.remove("LodestoneTracked");
}
});
}
use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class ShieldItemStackData method layerToNbt.
public static CompoundTag layerToNbt(final BannerPatternLayer layer) {
final CompoundTag nbt = new CompoundTag();
nbt.putString(Constants.TileEntity.Banner.BANNER_PATTERN_ID, ((BannerPattern) (Object) layer.shape()).getHashname());
nbt.putInt(Constants.TileEntity.Banner.BANNER_PATTERN_COLOR, ((net.minecraft.world.item.DyeColor) (Object) layer.color()).getId());
return nbt;
}
use of net.minecraft.nbt.CompoundTag in project SpongeCommon by SpongePowered.
the class BookPagesItemStackData method get.
// @formatter:on
private static List<Enchantment> get(final ItemStack holder, final String nbtKey) {
final CompoundTag tag = holder.getTag();
if (tag == null || !tag.contains(nbtKey, Constants.NBT.TAG_LIST)) {
return new ArrayList<>();
}
final ListTag list = tag.getList(nbtKey, Constants.NBT.TAG_COMPOUND);
return NBTStreams.toCompounds(list).map(BookPagesItemStackData::enchantmentFromNbt).filter(Objects::nonNull).collect(Collectors.toList());
}
Aggregations