/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2024 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.core;

import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.syncher.SynchedEntityData;

import java.util.ArrayList;

public class ChatWrapper21 implements ChatWrapper {
    @Override
    public Object stringToChatComponent(String text) {
        return MutableComponent.create(PlainTextContents.create(text));
    }

    @Override
    public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) {
        ArrayList<SynchedEntityData.DataValue<?>> nativeWatchers = new ArrayList<>(1);
        for(int i = 0; i < dataWatcherKeyValues.length; i+=2) {
            nativeWatchers.add(((SynchedEntityData.DataItem<?>) BountifulWrapper.impl.getDataWatcherItem(dataWatcherKeyValues[i], dataWatcherKeyValues[i+1])).value());
        }

        return new ClientboundSetEntityDataPacket(entityId, nativeWatchers);
    }
}
