use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class PrimaryLevelDataMixin method bridge$writeSpongeLevelData.
@Override
public CompoundTag bridge$writeSpongeLevelData() {
final CompoundTag data = new CompoundTag();
data.putUUID(Constants.Sponge.World.UNIQUE_ID, this.bridge$uniqueId());
// Map Storage
final CompoundTag mapUUIDIndexTag = new CompoundTag();
MapUtil.saveMapUUIDIndex(mapUUIDIndexTag, this.bridge$getMapUUIDIndex());
data.put(Constants.Map.MAP_UUID_INDEX, mapUUIDIndexTag);
final ListTag playerIdList = new ListTag();
data.put(Constants.Sponge.SPONGE_PLAYER_UUID_TABLE, playerIdList);
this.impl$pendingUniqueIds.forEach(uuid -> playerIdList.add(new IntArrayTag(SerializableUUID.uuidToIntArray(uuid))));
this.impl$pendingUniqueIds.clear();
return data;
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class ChunkSerializerMixin_Tracker method impl$writeSpongeLevelData.
@Inject(method = "write", at = @At(value = "RETURN"))
private static void impl$writeSpongeLevelData(final ServerLevel param0, final ChunkAccess param1, final CallbackInfoReturnable<CompoundTag> cir) {
if (!(param1 instanceof LevelChunk)) {
return;
}
final LevelChunkBridge chunk = (LevelChunkBridge) param1;
if (!chunk.bridge$getTrackedShortPlayerPositions().isEmpty() || !chunk.bridge$getTrackedIntPlayerPositions().isEmpty()) {
final CompoundTag level = (CompoundTag) cir.getReturnValue().get("Level");
final CompoundTag trackedNbt = new CompoundTag();
final ListTag positions = new ListTag();
trackedNbt.put(Constants.Sponge.SPONGE_BLOCK_POS_TABLE, positions);
level.put(Constants.Sponge.Data.V2.SPONGE_DATA, trackedNbt);
ChunkSerializerMixin_Tracker.impl$writeMap(positions, chunk.bridge$getTrackedShortPlayerPositions(), (nbt, pos) -> nbt.putShort("pos", pos));
ChunkSerializerMixin_Tracker.impl$writeMap(positions, chunk.bridge$getTrackedIntPlayerPositions(), (nbt, pos) -> nbt.putInt("ipos", pos));
}
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class ChunkSerializerMixin_Tracker method impl$readSpongeLevelData.
@Redirect(method = "read", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/ChunkAccess;setLightCorrect(Z)V"))
private static void impl$readSpongeLevelData(final ChunkAccess chunkAccess, final boolean var1, final ServerLevel param0, final StructureManager param1, final PoiManager param2, final ChunkPos param3, final CompoundTag param4) {
if (!(chunkAccess instanceof LevelChunk)) {
return;
}
final CompoundTag level = (CompoundTag) param4.get("Level");
final CompoundTag spongeData = level.getCompound(Constants.Sponge.Data.V2.SPONGE_DATA);
if (spongeData.isEmpty()) {
return;
}
final Map<Integer, PlayerTracker> trackedIntPlayerPositions = new HashMap<>();
final Map<Short, PlayerTracker> trackedShortPlayerPositions = new HashMap<>();
final ListTag list = spongeData.getList(Constants.Sponge.SPONGE_BLOCK_POS_TABLE, 10);
final LevelChunkBridge chunk = (LevelChunkBridge) chunkAccess;
for (Tag tag : list) {
final PlayerTracker tracker = new PlayerTracker();
final CompoundTag data = (CompoundTag) tag;
final boolean isShortPos = data.contains("pos");
if (data.contains("owner")) {
tracker.creatorindex = data.getInt("owner");
}
if (data.contains("notifier")) {
tracker.notifierIndex = data.getInt("notifier");
}
if (tracker.notifierIndex != -1 || tracker.creatorindex != -1) {
if (isShortPos) {
trackedShortPlayerPositions.put(data.getShort("pos"), tracker);
} else {
trackedIntPlayerPositions.put(data.getInt("ipos"), tracker);
}
}
}
chunk.bridge$setTrackedIntPlayerPositions(trackedIntPlayerPositions);
chunk.bridge$setTrackedShortPlayerPositions(trackedShortPlayerPositions);
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class ShieldItemStackData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ItemStack.class).create(Keys.DYE_COLOR).get(h -> {
final CompoundTag tag = h.getTagElement(Constants.Item.BLOCK_ENTITY_TAG);
if (tag == null || tag.contains(Constants.TileEntity.Banner.BANNER_PATTERNS, Constants.NBT.TAG_LIST)) {
return DyeColors.WHITE.get();
}
final int id = tag.getInt(Constants.TileEntity.Banner.BANNER_BASE);
return (DyeColor) (Object) net.minecraft.world.item.DyeColor.byId(id);
}).set((h, v) -> {
final CompoundTag tag = h.getOrCreateTagElement(Constants.Item.BLOCK_ENTITY_TAG);
tag.putInt(Constants.TileEntity.Banner.BANNER_BASE, ((net.minecraft.world.item.DyeColor) (Object) v).getId());
}).supports(h -> h.getItem() instanceof ShieldItem).create(Keys.BANNER_PATTERN_LAYERS).get(h -> {
final CompoundTag tag = h.getTagElement(Constants.Item.BLOCK_ENTITY_TAG);
if (tag == null || !tag.contains(Constants.TileEntity.Banner.BANNER_PATTERNS, Constants.NBT.TAG_LIST)) {
return new ArrayList<>();
}
final ListTag layersList = tag.getList(Constants.TileEntity.Banner.BANNER_PATTERNS, Constants.NBT.TAG_COMPOUND);
return layersList.stream().map(layer -> ShieldItemStackData.layerFromNbt((CompoundTag) layer)).collect(Collectors.toList());
}).set((h, v) -> {
final ListTag layersTag = v.stream().filter(layer -> layer.shape() != BannerPatternShapes.BASE.get()).map(ShieldItemStackData::layerToNbt).collect(NBTCollectors.toTagList());
final CompoundTag blockEntity = h.getOrCreateTagElement(Constants.Item.BLOCK_ENTITY_TAG);
blockEntity.put(Constants.TileEntity.Banner.BANNER_PATTERNS, layersTag);
if (h.getItem() instanceof ShieldItem) {
// TODO reject BannerPatternShapes.BASE for BannerItem?
v.stream().filter(layer -> layer.shape() == BannerPatternShapes.BASE.get()).forEach(layer -> {
blockEntity.putInt(Constants.TileEntity.Banner.BANNER_BASE, ((net.minecraft.world.item.DyeColor) (Object) layer.color()).getId());
});
}
}).supports(h -> h.getItem() instanceof ShieldItem || h.getItem() instanceof BannerItem);
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class BookPagesItemStackData method set.
private static boolean set(final ItemStack holder, final List<Enchantment> value, final Function<List<Enchantment>, Stream<Enchantment>> filter, final String nbtKey) {
if (value.isEmpty()) {
return BookPagesItemStackData.delete(holder, nbtKey);
}
final CompoundTag tag = holder.getOrCreateTag();
final ListTag list = filter.apply(value).map(BookPagesItemStackData::enchantmentToNbt).collect(NBTCollectors.toTagList());
tag.put(nbtKey, list);
return true;
}
Aggregations