From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Wed, 28 Dec 2016 07:18:33 +0100 Subject: [PATCH] Firework API's diff --git a/src/main/java/net/minecraft/nbt/CompoundTag.java b/src/main/java/net/minecraft/nbt/CompoundTag.java index 4c8f249e45e5deb7628997d4dbd9dab613ac5241..a91bf94ed9f2f353a685194fc91c4b101ccc1232 100644 --- a/src/main/java/net/minecraft/nbt/CompoundTag.java +++ b/src/main/java/net/minecraft/nbt/CompoundTag.java @@ -153,6 +153,7 @@ public class CompoundTag implements Tag { return NbtUtils.loadUUID(this.get(key)); } + public final boolean hasUUID(String s) { return this.hasUUID(s); } // Paper - OBFHELPER public boolean hasUUID(String key) { Tag nbtbase = this.get(key); 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 28a2c6a0fbc8b4c38f3899698504d8ca0d7ba3af..5669be107b580075fdffbcbb490513593a57fc9f 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java +++ b/src/main/java/net/minecraft/world/entity/projectile/FireworkRocketEntity.java @@ -37,7 +37,8 @@ public class FireworkRocketEntity extends Projectile { public static final EntityDataAccessor DATA_SHOT_AT_ANGLE = SynchedEntityData.defineId(FireworkRocketEntity.class, EntityDataSerializers.BOOLEAN); private int life; public int lifetime; - private LivingEntity attachedToEntity; + public LivingEntity attachedToEntity; // Paper - public + public java.util.UUID spawningEntity; // Paper public FireworkRocketEntity(EntityType type, Level world) { super(type, world); @@ -284,6 +285,11 @@ public class FireworkRocketEntity extends Projectile { } tag.putBoolean("ShotAtAngle", (Boolean) this.entityData.get(FireworkRocketEntity.DATA_SHOT_AT_ANGLE)); + // Paper start + if (this.spawningEntity != null) { + tag.setUUID("SpawningEntity", this.spawningEntity); + } + // Paper end } @Override @@ -300,7 +306,11 @@ public class FireworkRocketEntity extends Projectile { if (tag.contains("ShotAtAngle")) { this.entityData.set(FireworkRocketEntity.DATA_SHOT_AT_ANGLE, tag.getBoolean("ShotAtAngle")); } - + // Paper start + if (tag.hasUUID("SpawningEntity")) { + this.spawningEntity = tag.getUUID("SpawningEntity"); + } + // Paper end } @Override diff --git a/src/main/java/net/minecraft/world/item/CrossbowItem.java b/src/main/java/net/minecraft/world/item/CrossbowItem.java index 8a358872d3c8357775451e7dffe267cf9121f211..e1e58b7035e6dbafdad0a04cc5333464fc4febb8 100644 --- a/src/main/java/net/minecraft/world/item/CrossbowItem.java +++ b/src/main/java/net/minecraft/world/item/CrossbowItem.java @@ -205,6 +205,7 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable { if (flag1) { object = new FireworkRocketEntity(world, projectile, shooter, shooter.getX(), shooter.getEyeY() - 0.15000000596046448D, shooter.getZ(), true); + ((FireworkRocketEntity) object).spawningEntity = shooter.getUUID(); // Paper } else { object = getArrow(world, shooter, crossbow, projectile); if (creative || simulated != 0.0F) { diff --git a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java index d3a045fc99ef77fa0905aac7c73a2e84772c73cf..dba52063d402eb2371441fa244b730a3313444fc 100644 --- a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java +++ b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java @@ -27,6 +27,7 @@ public class FireworkRocketItem extends Item { Vec3 vec3d = context.getClickLocation(); Direction enumdirection = context.getClickedFace(); FireworkRocketEntity entityfireworks = new FireworkRocketEntity(world, context.getPlayer(), vec3d.x + (double) enumdirection.getStepX() * 0.15D, vec3d.y + (double) enumdirection.getStepY() * 0.15D, vec3d.z + (double) enumdirection.getStepZ() * 0.15D, itemstack); + entityfireworks.spawningEntity = context.getPlayer().getUUID(); // Paper world.addFreshEntity(entityfireworks); itemstack.shrink(1); @@ -41,7 +42,11 @@ public class FireworkRocketItem extends Item { ItemStack itemstack = user.getItemInHand(hand); if (!world.isClientSide) { - world.addFreshEntity(new FireworkRocketEntity(world, itemstack, user)); + // Paper start + final FireworkRocketEntity entityfireworks = new FireworkRocketEntity(world, itemstack, user); + entityfireworks.spawningEntity = user.getUUID(); + world.addFreshEntity(entityfireworks); + // Paper end if (!user.abilities.instabuild) { itemstack.shrink(1); } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java index 5901a53b25449430ed02a80b022f83755f83a440..0fbbdd6e3fda3f834d0b0d68d868dbff1aebb673 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.entity; import java.util.Random; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.FireworkRocketEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -78,4 +79,17 @@ public class CraftFirework extends CraftProjectile implements Firework { public void setShotAtAngle(boolean shotAtAngle) { getHandle().getEntityData().set(FireworkRocketEntity.DATA_SHOT_AT_ANGLE, shotAtAngle); } + + // Paper start + @Override + public java.util.UUID getSpawningEntity() { + return getHandle().spawningEntity; + } + + @Override + public org.bukkit.entity.LivingEntity getBoostedEntity() { + LivingEntity boostedEntity = getHandle().attachedToEntity; + return boostedEntity != null ? (org.bukkit.entity.LivingEntity) boostedEntity.getBukkitEntity() : null; + } + // Paper end }