Fix NPEs in CrossbowItem

This commit is contained in:
Camotoy 2023-04-11 13:15:17 -04:00
parent e542e01994
commit d22ee51633
No known key found for this signature in database
GPG Key ID: 7EEFB66FE798081F
1 changed files with 6 additions and 5 deletions

View File

@ -32,6 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.inventory.item.ItemTranslator;
import org.jetbrains.annotations.Nullable;
public class CrossbowItem extends Item {
public CrossbowItem(String javaIdentifier, Builder builder) {
@ -45,12 +46,12 @@ public class CrossbowItem extends Item {
ListTag chargedProjectiles = tag.get("ChargedProjectiles");
if (chargedProjectiles != null) {
if (!chargedProjectiles.getValue().isEmpty()) {
CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0);
CompoundTag javaProjectileAsNbt = (CompoundTag) chargedProjectiles.getValue().get(0);
ItemMapping projectileMapping = session.getItemMappings().getMapping((String) projectile.get("id").getValue());
ItemMapping projectileMapping = session.getItemMappings().getMapping((String) javaProjectileAsNbt.get("id").getValue());
if (projectileMapping == null) return;
CompoundTag projectileTag = projectile.get("tag");
ItemStack itemStack = new ItemStack(projectileMapping.getJavaItem().javaId(), (byte) projectile.get("Count").getValue(), projectileTag);
@Nullable CompoundTag projectileTag = javaProjectileAsNbt.get("tag");
ItemStack itemStack = new ItemStack(projectileMapping.getJavaItem().javaId(), (byte) javaProjectileAsNbt.get("Count").getValue(), projectileTag);
ItemData itemData = ItemTranslator.translateToBedrock(session, itemStack);
CompoundTag newProjectile = new CompoundTag("chargedItem");
@ -59,7 +60,7 @@ public class CrossbowItem extends Item {
newProjectile.put(new ShortTag("Damage", (short) itemData.getDamage()));
projectileTag.put(newProjectile);
tag.put(newProjectile);
}
}
}