Ensure the item sent isn't air (#7584)

This commit is contained in:
Owen1212055 2022-03-12 15:34:03 -05:00
parent 35cc32c4a1
commit ac137edbc7

View File

@ -60,11 +60,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@Override
public void setFireworkMeta(FireworkMeta meta) {
- this.item.setItemMeta(meta);
+ applyFireworkEffect(meta); // Paper - Expose firework item directly
// Copied from EntityFireworks constructor, update firework lifetime/power
this.getHandle().lifetime = 10 * (1 + meta.getPower()) + this.random.nextInt(6) + this.random.nextInt(7);
@@ -0,0 +0,0 @@ public class CraftFirework extends CraftProjectile implements Firework {
return boostedEntity != null ? (org.bukkit.entity.LivingEntity) boostedEntity.getBukkitEntity() : null;
}
@ -78,7 +77,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ @Override
+ public void setItem(org.bukkit.inventory.ItemStack itemStack) {
+ FireworkMeta meta = getFireworkMeta();
+ var nmsItem = itemStack == null ? ItemStack.EMPTY : CraftItemStack.asNMSCopy(itemStack);
+ ItemStack nmsItem = itemStack == null ? ItemStack.EMPTY : CraftItemStack.asNMSCopy(itemStack);
+ this.getHandle().getEntityData().set(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM, nmsItem);
+
+ applyFireworkEffect(meta);
@ -105,7 +104,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ void applyFireworkEffect(FireworkMeta meta) {
+ CraftItemStack.applyMetaToItem(this.getHandle().getEntityData().get(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM), meta);
+ ItemStack item = this.getHandle().getItem();
+ CraftItemStack.applyMetaToItem(item, meta);
+
+ this.getHandle().getEntityData().set(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM, item);
+ }
+ // Paper end - Expose firework item directly + manually setting flight
}
@ -133,8 +135,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ @Override
+ public void setPotionMeta(org.bukkit.inventory.meta.PotionMeta meta) {
+ CraftItemStack.applyMetaToItem(this.getHandle().getItemRaw(), meta);
+ this.getHandle().setItem(this.getHandle().getItemRaw()); // Reset item
+ net.minecraft.world.item.ItemStack item = this.getHandle().getItem();
+ CraftItemStack.applyMetaToItem(item, meta);
+ this.getHandle().setItem(item); // Reset item
+ }
+ // Paper end
@Override