224 lines
11 KiB
Diff
224 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
|
Date: Tue, 22 Jun 2021 23:41:11 -0400
|
|
Subject: [PATCH] More Projectile API
|
|
|
|
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
|
|
index fee09e6ff72cf1da389d5811dd005642cd50a5b4..4f276b2a86735a2c664738450ae0fbdd82031d4e 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
|
|
@@ -98,6 +98,11 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
|
|
@Override
|
|
protected void onHit(HitResult hitResult) {
|
|
super.onHit(hitResult);
|
|
+ // Paper start - More projectile API
|
|
+ this.splash(hitResult);
|
|
+ }
|
|
+ public void splash(@org.jetbrains.annotations.Nullable HitResult hitResult) {
|
|
+ // Paper end - More projectile API
|
|
if (!this.level.isClientSide) {
|
|
ItemStack itemstack = this.getItem();
|
|
Potion potionregistry = PotionUtils.getPotion(itemstack);
|
|
@@ -110,7 +115,7 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
|
|
if (this.isLingering()) {
|
|
this.makeAreaOfEffectCloud(itemstack, potionregistry);
|
|
} else {
|
|
- this.applySplash(list, hitResult.getType() == HitResult.Type.ENTITY ? ((EntityHitResult) hitResult).getEntity() : null);
|
|
+ this.applySplash(list, hitResult != null && hitResult.getType() == HitResult.Type.ENTITY ? ((EntityHitResult) hitResult).getEntity() : null); // Paper - nullable hitResult
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
|
|
index c242f654c88ca1773429348939d3bb2ffae3768c..d1c7ab67cba881d96b7a5e9220130d86d0514304 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
|
|
@@ -16,24 +16,26 @@ import org.bukkit.inventory.meta.FireworkMeta;
|
|
public class CraftFirework extends CraftProjectile implements Firework {
|
|
|
|
private final Random random = new Random();
|
|
- private final CraftItemStack item;
|
|
+ //private CraftItemStack item; // Paper - Remove usage, not accurate representation of current item.
|
|
|
|
public CraftFirework(CraftServer server, FireworkRocketEntity entity) {
|
|
super(server, entity);
|
|
|
|
- ItemStack item = this.getHandle().getEntityData().get(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM);
|
|
-
|
|
- if (item.isEmpty()) {
|
|
- item = new ItemStack(Items.FIREWORK_ROCKET);
|
|
- this.getHandle().getEntityData().set(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM, item);
|
|
- }
|
|
-
|
|
- this.item = CraftItemStack.asCraftMirror(item);
|
|
-
|
|
- // Ensure the item is a firework...
|
|
- if (this.item.getType() != Material.FIREWORK_ROCKET) {
|
|
- this.item.setType(Material.FIREWORK_ROCKET);
|
|
- }
|
|
+// Paper Start - Expose firework item directly
|
|
+// ItemStack item = this.getHandle().getEntityData().get(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM);
|
|
+//
|
|
+// if (item.isEmpty()) {
|
|
+// item = new ItemStack(Items.FIREWORK_ROCKET);
|
|
+// this.getHandle().getEntityData().set(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM, item);
|
|
+// }
|
|
+//
|
|
+// this.item = CraftItemStack.asCraftMirror(item);
|
|
+//
|
|
+// // Ensure the item is a firework...
|
|
+// if (this.item.getType() != Material.FIREWORK_ROCKET) {
|
|
+// this.item.setType(Material.FIREWORK_ROCKET);
|
|
+// }
|
|
+ // Paper End - Expose firework item directly
|
|
}
|
|
|
|
@Override
|
|
@@ -53,12 +55,12 @@ public class CraftFirework extends CraftProjectile implements Firework {
|
|
|
|
@Override
|
|
public FireworkMeta getFireworkMeta() {
|
|
- return (FireworkMeta) this.item.getItemMeta();
|
|
+ return (FireworkMeta) CraftItemStack.getItemMeta(this.getHandle().getEntityData().get(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM), Material.FIREWORK_ROCKET); // Paper - Expose firework item directly
|
|
}
|
|
|
|
@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);
|
|
@@ -142,4 +144,46 @@ public class CraftFirework extends CraftProjectile implements Firework {
|
|
return getHandle().spawningEntity;
|
|
}
|
|
// Paper end
|
|
+ // Paper start - Expose firework item directly + manually setting flight
|
|
+ @Override
|
|
+ public org.bukkit.inventory.ItemStack getItem() {
|
|
+ return CraftItemStack.asBukkitCopy(this.getHandle().getItem());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setItem(org.bukkit.inventory.ItemStack itemStack) {
|
|
+ FireworkMeta meta = getFireworkMeta();
|
|
+ ItemStack nmsItem = itemStack == null ? ItemStack.EMPTY : CraftItemStack.asNMSCopy(itemStack);
|
|
+ this.getHandle().getEntityData().set(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM, nmsItem);
|
|
+
|
|
+ applyFireworkEffect(meta);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getTicksFlown() {
|
|
+ return this.getHandle().life;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setTicksFlown(int ticks) {
|
|
+ this.getHandle().life = ticks;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getTicksToDetonate() {
|
|
+ return this.getHandle().lifetime;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setTicksToDetonate(int ticks) {
|
|
+ this.getHandle().lifetime = ticks;
|
|
+ }
|
|
+
|
|
+ void applyFireworkEffect(FireworkMeta 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
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
|
|
index 6bfa984781a483d048ef4318761203c701d8a632..5e0c2c5094e1578162d1a50d50701fbd25e6d961 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFishHook.java
|
|
@@ -119,4 +119,15 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
|
public HookState getState() {
|
|
return HookState.values()[this.getHandle().currentState.ordinal()];
|
|
}
|
|
+ // Paper start - More FishHook API
|
|
+ @Override
|
|
+ public int getWaitTime() {
|
|
+ return this.getHandle().timeUntilLured;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setWaitTime(int ticks) {
|
|
+ this.getHandle().timeUntilLured = ticks;
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java
|
|
index 0db8aa840ea026d48215ac5dc80ffde5f12725b1..397e0df15a0e64e5bc522f62f3b327a5039ec4c8 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java
|
|
@@ -39,11 +39,31 @@ public class CraftThrownPotion extends CraftThrowableProjectile implements Throw
|
|
Validate.notNull(item, "ItemStack cannot be null.");
|
|
|
|
// The ItemStack must be a potion.
|
|
- Validate.isTrue(item.getType() == Material.LINGERING_POTION || item.getType() == Material.SPLASH_POTION, "ItemStack must be a lingering or splash potion. This item stack was " + item.getType() + ".");
|
|
+ //Validate.isTrue(item.getType() == Material.LINGERING_POTION || item.getType() == Material.SPLASH_POTION, "ItemStack must be a lingering or splash potion. This item stack was " + item.getType() + "."); // Paper - Projectile API
|
|
+ org.bukkit.inventory.meta.PotionMeta meta = (item.getType() == Material.LINGERING_POTION || item.getType() == Material.SPLASH_POTION) ? null : this.getPotionMeta(); // Paper - Projectile API
|
|
|
|
this.getHandle().setItem(CraftItemStack.asNMSCopy(item));
|
|
+ if (meta != null) this.setPotionMeta(meta); // Paper - Projectile API
|
|
}
|
|
|
|
+ // Paper start - Projectile API
|
|
+ @Override
|
|
+ public org.bukkit.inventory.meta.PotionMeta getPotionMeta() {
|
|
+ return (org.bukkit.inventory.meta.PotionMeta) CraftItemStack.getItemMeta(this.getHandle().getItemRaw(), Material.SPLASH_POTION);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setPotionMeta(org.bukkit.inventory.meta.PotionMeta meta) {
|
|
+ net.minecraft.world.item.ItemStack item = this.getHandle().getItem();
|
|
+ CraftItemStack.applyMetaToItem(item, meta);
|
|
+ this.getHandle().setItem(item); // Reset item
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void splash() {
|
|
+ this.getHandle().splash(null);
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public net.minecraft.world.entity.projectile.ThrownPotion getHandle() {
|
|
return (net.minecraft.world.entity.projectile.ThrownPotion) entity;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
index f3abcd5949011eaef3d1ba68f4cc0751042d2834..bfb1ad0b6e20e10fee53f94a3e6c4f8aad7aae7d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
@@ -278,12 +278,20 @@ public final class CraftItemStack extends ItemStack {
|
|
public ItemMeta getItemMeta() {
|
|
return CraftItemStack.getItemMeta(this.handle);
|
|
}
|
|
+ // Paper start
|
|
+ public static void applyMetaToItem(net.minecraft.world.item.ItemStack itemStack, ItemMeta meta) {
|
|
+ ((org.bukkit.craftbukkit.inventory.CraftMetaItem) meta).applyToItem(itemStack.getOrCreateTag());
|
|
+ }
|
|
|
|
public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item) {
|
|
+ return getItemMeta(item, CraftItemStack.getType(item));
|
|
+ }
|
|
+ public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item, Material material) {
|
|
+ // Paper end
|
|
if (!CraftItemStack.hasItemMeta(item)) {
|
|
- return CraftItemFactory.instance().getItemMeta(CraftItemStack.getType(item));
|
|
+ return CraftItemFactory.instance().getItemMeta(material); // Paper
|
|
}
|
|
- switch (CraftItemStack.getType(item)) {
|
|
+ switch (material) { // Paper
|
|
case WRITTEN_BOOK:
|
|
return new CraftMetaBookSigned(item.getTag());
|
|
case WRITABLE_BOOK:
|