aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/unapplied/server/0120-Firework-API-s.patch
blob: 5efca78eb3bff3a4a2d5bb3e90dbda19146668eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 28 Dec 2016 07:18:33 +0100
Subject: [PATCH] Firework API's

== AT ==
public net.minecraft.world.entity.projectile.FireworkRocketEntity attachedToEntity

diff --git a/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java b/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java
index e5d245c71ce2b2a1fe7f156e69831dec73354221..8a4e7e1c0c4919d2ee34121c14f9665b9ad95273 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java
@@ -45,6 +45,7 @@ public class FireworkRocketEntity extends Projectile implements ItemSupplier {
     public int lifetime;
     @Nullable
     public LivingEntity attachedToEntity;
+    @Nullable public java.util.UUID spawningEntity; // Paper
 
     public FireworkRocketEntity(EntityType<? extends FireworkRocketEntity> type, Level world) {
         super(type, world);
@@ -324,6 +325,11 @@ public class FireworkRocketEntity extends Projectile implements ItemSupplier {
         nbt.putInt("LifeTime", this.lifetime);
         nbt.put("FireworksItem", this.getItem().save(this.registryAccess()));
         nbt.putBoolean("ShotAtAngle", (Boolean) this.entityData.get(FireworkRocketEntity.DATA_SHOT_AT_ANGLE));
+        // Paper start
+        if (this.spawningEntity != null) {
+            nbt.putUUID("SpawningEntity", this.spawningEntity);
+        }
+        // Paper end
     }
 
     @Override
@@ -340,7 +346,11 @@ public class FireworkRocketEntity extends Projectile implements ItemSupplier {
         if (nbt.contains("ShotAtAngle")) {
             this.entityData.set(FireworkRocketEntity.DATA_SHOT_AT_ANGLE, nbt.getBoolean("ShotAtAngle"));
         }
-
+        // Paper start
+        if (nbt.hasUUID("SpawningEntity")) {
+            this.spawningEntity = nbt.getUUID("SpawningEntity");
+        }
+        // Paper end
     }
 
     private List<FireworkExplosion> getExplosions() {
diff --git a/src/main/java/net/minecraft/world/item/CrossbowItem.java b/src/main/java/net/minecraft/world/item/CrossbowItem.java
index 40cae3332a18e3f7be890d2ba8014bfe3d2d1c0e..710181cf04563f06690eee5b46a5a0d84844ac29 100644
--- a/src/main/java/net/minecraft/world/item/CrossbowItem.java
+++ b/src/main/java/net/minecraft/world/item/CrossbowItem.java
@@ -163,7 +163,11 @@ public class CrossbowItem extends ProjectileWeaponItem {
     @Override
     protected Projectile createProjectile(Level world, LivingEntity shooter, ItemStack weaponStack, ItemStack projectileStack, boolean critical) {
         if (projectileStack.is(Items.FIREWORK_ROCKET)) {
-            return new FireworkRocketEntity(world, projectileStack, shooter, shooter.getX(), shooter.getEyeY() - 0.15F, shooter.getZ(), true);
+            // Paper start
+            FireworkRocketEntity entity =  new FireworkRocketEntity(world, projectileStack, shooter, shooter.getX(), shooter.getEyeY() - 0.15F, shooter.getZ(), true);
+            entity.spawningEntity = shooter.getUUID(); // Paper
+            return entity;
+            // Paper end
         } else {
             Projectile projectile = super.createProjectile(world, shooter, weaponStack, projectileStack, critical);
             if (projectile instanceof AbstractArrow abstractArrow) {
diff --git a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
index 100a66b9211429b5c32f9ed226c7ddafb9c7df81..3929cb76f1c98c0a22eb2ab64c2ed09805ffe448 100644
--- a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
+++ b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
@@ -43,7 +43,7 @@ public class FireworkRocketItem extends Item implements ProjectileItem {
                     itemStack
                 ),
                 serverLevel,
-                itemStack
+                itemStack, f -> f.spawningEntity = context.getPlayer() == null ? null : context.getPlayer().getUUID()  // Paper - firework api - assign spawning entity uuid
             );
             itemStack.shrink(1);
         }
@@ -56,7 +56,7 @@ public class FireworkRocketItem extends Item implements ProjectileItem {
         if (user.isFallFlying()) {
             ItemStack itemStack = user.getItemInHand(hand);
             if (world instanceof ServerLevel serverLevel) {
-                Projectile.spawnProjectile(new FireworkRocketEntity(world, itemStack, user), serverLevel, itemStack);
+                Projectile.spawnProjectile(new FireworkRocketEntity(world, itemStack, user), serverLevel, itemStack, f -> f.spawningEntity = user.getUUID());  // Paper - firework api - assign spawning entity uuid
                 itemStack.consume(1, user);
                 user.awardStat(Stats.ITEM_USED.get(this));
             }
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
index 5ae87c370e47c545cef27a36e40da137e1ec656b..c9e15a9d82dee935293b2e7e233f5b9b2d822448 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
@@ -129,4 +129,11 @@ public class CraftFirework extends CraftProjectile implements Firework {
     public void setShotAtAngle(boolean shotAtAngle) {
         this.getHandle().getEntityData().set(FireworkRocketEntity.DATA_SHOT_AT_ANGLE, shotAtAngle);
     }
+
+    // Paper start
+    @Override
+    public java.util.UUID getSpawningEntity() {
+        return getHandle().spawningEntity;
+    }
+    // Paper end
 }