2020-05-24 19:51:30 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2020-05-24 19:51:30 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.network.translators.item.translators.nbt;
|
2020-05-24 19:51:30 +00:00
|
|
|
|
2020-10-09 00:40:50 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
|
|
|
import com.github.steveice10.opennbt.tag.builtin.*;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.network.session.GeyserSession;
|
|
|
|
import org.geysermc.geyser.network.translators.ItemRemapper;
|
|
|
|
import org.geysermc.geyser.network.translators.item.ItemTranslator;
|
|
|
|
import org.geysermc.geyser.network.translators.item.NbtItemStackTranslator;
|
|
|
|
import org.geysermc.geyser.registry.type.ItemMapping;
|
2020-05-24 19:51:30 +00:00
|
|
|
|
|
|
|
@ItemRemapper
|
|
|
|
public class CrossbowTranslator extends NbtItemStackTranslator {
|
|
|
|
|
|
|
|
@Override
|
2021-07-13 01:19:40 +00:00
|
|
|
public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemMapping mapping) {
|
2020-05-24 19:51:30 +00:00
|
|
|
if (itemTag.get("ChargedProjectiles") != null) {
|
|
|
|
ListTag chargedProjectiles = itemTag.get("ChargedProjectiles");
|
|
|
|
if (!chargedProjectiles.getValue().isEmpty()) {
|
|
|
|
CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0);
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
ItemMapping projectileMapping = session.getItemMappings().getMapping((String) projectile.get("id").getValue());
|
|
|
|
if (projectileMapping == null) return;
|
2020-10-09 00:40:50 +00:00
|
|
|
CompoundTag tag = projectile.get("tag");
|
2021-07-13 01:19:40 +00:00
|
|
|
ItemStack itemStack = new ItemStack(mapping.getJavaId(), (byte) projectile.get("Count").getValue(), tag);
|
2020-10-09 00:40:50 +00:00
|
|
|
ItemData itemData = ItemTranslator.translateToBedrock(session, itemStack);
|
|
|
|
|
2020-05-24 19:51:30 +00:00
|
|
|
CompoundTag newProjectile = new CompoundTag("chargedItem");
|
2020-10-09 00:40:50 +00:00
|
|
|
newProjectile.put(new ByteTag("Count", (byte) itemData.getCount()));
|
2021-07-13 01:19:40 +00:00
|
|
|
newProjectile.put(new StringTag("Name", projectileMapping.getBedrockIdentifier()));
|
2020-05-24 19:51:30 +00:00
|
|
|
|
2021-04-06 04:14:06 +00:00
|
|
|
newProjectile.put(new ShortTag("Damage", (short) itemData.getDamage()));
|
2020-05-24 19:51:30 +00:00
|
|
|
|
|
|
|
itemTag.put(newProjectile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-13 01:19:40 +00:00
|
|
|
public void translateToJava(CompoundTag itemTag, ItemMapping mapping) {
|
2020-05-24 19:51:30 +00:00
|
|
|
if (itemTag.get("chargedItem") != null) {
|
|
|
|
CompoundTag chargedItem = itemTag.get("chargedItem");
|
|
|
|
|
|
|
|
CompoundTag newProjectile = new CompoundTag("");
|
|
|
|
newProjectile.put(new ByteTag("Count", (byte) chargedItem.get("Count").getValue()));
|
|
|
|
newProjectile.put(new StringTag("id", (String) chargedItem.get("Name").getValue()));
|
|
|
|
|
|
|
|
ListTag chargedProjectiles = new ListTag("ChargedProjectiles");
|
|
|
|
chargedProjectiles.add(newProjectile);
|
|
|
|
|
|
|
|
itemTag.put(chargedProjectiles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-13 01:19:40 +00:00
|
|
|
public boolean acceptItem(ItemMapping mapping) {
|
|
|
|
return "minecraft:crossbow".equals(mapping.getJavaIdentifier());
|
2020-05-24 19:51:30 +00:00
|
|
|
}
|
|
|
|
}
|