Archiviert
13
0

Update projectile launch to 1.21.2

Dieser Commit ist enthalten in:
Bjarne Koll 2024-10-23 12:02:36 +02:00
Ursprung dc5af4848a
Commit 7c04a31c9f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 27F6CCCF55D2EE62
4 geänderte Dateien mit 452 neuen und 396 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,75 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 21 Jul 2018 01:59:59 -0500
Subject: [PATCH] PlayerElytraBoostEvent
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
index 3b0b543a1bf8b190620fd4385751f05db74a47f1..9a6701f4ceed680ee12224802f01ce399798b6e1 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
@@ -219,11 +219,34 @@ public abstract class Projectile extends Entity implements TraceableEntity {
});
}
+ // Paper start - delayed projectile spawning
+ public record Delayed<T extends Projectile>(
+ T projectile,
+ ServerLevel world,
+ ItemStack projectileStack
+ ) {
+ // Taken from net.minecraft.world.entity.projectile.Projectile.spawnProjectile(T, net.minecraft.server.level.ServerLevel, net.minecraft.world.item.ItemStack, java.util.function.Consumer<T>)
+ public boolean attemptSpawn() {
+ if (!world.addFreshEntity(projectile)) return false;
+ projectile.applyOnProjectileSpawned(this.world, this.projectileStack);
+ return true;
+ }
+
+ public T spawn() {
+ this.attemptSpawn();
+ return projectile();
+ }
+ }
+ // Paper end - delayed projectile spawning
+
public static <T extends Projectile> T spawnProjectile(T projectile, ServerLevel world, ItemStack projectileStack, Consumer<T> beforeSpawn) {
+ // Paper start - delayed projectile spawning
+ return spawnProjectileDelayed(projectile, world, projectileStack, beforeSpawn).spawn();
+ }
+ public static <T extends Projectile> Delayed<T> spawnProjectileDelayed(T projectile, ServerLevel world, ItemStack projectileStack, Consumer<T> beforeSpawn) {
+ // Paper end - delayed projectile spawning
beforeSpawn.accept(projectile);
- if (world.addFreshEntity(projectile)) // CraftBukkit
- projectile.applyOnProjectileSpawned(world, projectileStack);
- return projectile;
+ return new Delayed<>(projectile, world, projectileStack); // Paper - delayed projectile spawning
}
public void applyOnProjectileSpawned(ServerLevel world, ItemStack projectileStack) {
diff --git a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
index 3929cb76f1c98c0a22eb2ab64c2ed09805ffe448..400ad0fa1d07c8b120e3c3b5488dfa315aa2d23f 100644
--- a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
+++ b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
@@ -56,9 +56,19 @@ 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, f -> f.spawningEntity = user.getUUID()); // Paper - firework api - assign spawning entity uuid
- itemStack.consume(1, user);
- user.awardStat(Stats.ITEM_USED.get(this));
+ // Paper start - PlayerElytraBoostEvent
+ final Projectile.Delayed<FireworkRocketEntity> delayed = Projectile.spawnProjectileDelayed(new FireworkRocketEntity(world, itemStack, user), serverLevel, itemStack, f -> f.spawningEntity = user.getUUID()); // Paper - firework api - assign spawning entity uuid
+ com.destroystokyo.paper.event.player.PlayerElytraBoostEvent event = new com.destroystokyo.paper.event.player.PlayerElytraBoostEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Firework) delayed.projectile().getBukkitEntity(), org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(hand));
+ if (event.callEvent() && delayed.attemptSpawn()) {
+ user.awardStat(Stats.ITEM_USED.get(this)); // Moved up from below
+ if (event.shouldConsume() && !user.hasInfiniteMaterials()) {
+ itemStack.shrink(1); // Moved up from below
+ } else ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ } else {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+ // Moved up consume/stat
+ // Paper end - PlayerElytraBoostEvent
}
return InteractionResult.SUCCESS;

Datei anzeigen

@ -0,0 +1,377 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 21 Jul 2018 03:11:03 -0500
Subject: [PATCH] PlayerLaunchProjectileEvent
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
index 9a6701f4ceed680ee12224802f01ce399798b6e1..55c0d23ea68cd328881bd40d6bfd12d58477d15b 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
@@ -197,7 +197,12 @@ public abstract class Projectile extends Entity implements TraceableEntity {
}
public static <T extends Projectile> T spawnProjectileFromRotation(Projectile.ProjectileFactory<T> creator, ServerLevel world, ItemStack projectileStack, LivingEntity shooter, float roll, float power, float divergence) {
- return Projectile.spawnProjectile(creator.create(world, shooter, projectileStack), world, projectileStack, (iprojectile) -> {
+ // Paper start - PlayerLaunchProjectileEvent
+ return spawnProjectileFromRotationDelayed(creator, world, projectileStack, shooter, roll, power, divergence).spawn();
+ }
+ public static <T extends Projectile> Delayed<T> spawnProjectileFromRotationDelayed(Projectile.ProjectileFactory<T> creator, ServerLevel world, ItemStack projectileStack, LivingEntity shooter, float roll, float power, float divergence) {
+ return Projectile.spawnProjectileDelayed(creator.create(world, shooter, projectileStack), world, projectileStack, (iprojectile) -> {
+ // Paper end - PlayerLaunchProjectileEvent
iprojectile.shootFromRotation(shooter, shooter.getXRot(), shooter.getYRot(), roll, power, divergence);
});
}
diff --git a/src/main/java/net/minecraft/world/item/EggItem.java b/src/main/java/net/minecraft/world/item/EggItem.java
index 8ddc1fa76244265616309322170c3a1b821c5092..3ddd34e5d05fa1355a2affd329d72dea216cd0e4 100644
--- a/src/main/java/net/minecraft/world/item/EggItem.java
+++ b/src/main/java/net/minecraft/world/item/EggItem.java
@@ -26,7 +26,19 @@ public class EggItem extends Item implements ProjectileItem {
// world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); // CraftBukkit - moved down
if (world instanceof ServerLevel worldserver) {
// CraftBukkit start
- if (Projectile.spawnProjectileFromRotation(ThrownEgg::new, worldserver, itemstack, user, 0.0F, 1.5F, 1.0F).isRemoved()) {
+ // Paper start - PlayerLaunchProjectileEvent
+ final Projectile.Delayed<ThrownEgg> thrownEgg = Projectile.spawnProjectileFromRotationDelayed(ThrownEgg::new, worldserver, itemstack, user, 0.0F, 1.5F, 1.0F);
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) thrownEgg.projectile().getBukkitEntity());
+ if (event.callEvent() && thrownEgg.attemptSpawn()) {
+ if (event.shouldConsume()) {
+ itemstack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.EGG_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
if (user instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
}
@@ -35,9 +47,7 @@ public class EggItem extends Item implements ProjectileItem {
// CraftBukkit end
}
world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.EGG_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
-
- user.awardStat(Stats.ITEM_USED.get(this));
- itemstack.consume(1, user);
+ // Paper - PlayerLaunchProjectileEvent - moved up
return InteractionResult.SUCCESS;
}
diff --git a/src/main/java/net/minecraft/world/item/EnderpearlItem.java b/src/main/java/net/minecraft/world/item/EnderpearlItem.java
index b9e24451a8f87479377e3324b3a956c0efc3e53c..b232390d8ee8e449e61c0ea7f3af60df507abb97 100644
--- a/src/main/java/net/minecraft/world/item/EnderpearlItem.java
+++ b/src/main/java/net/minecraft/world/item/EnderpearlItem.java
@@ -23,7 +23,20 @@ public class EnderpearlItem extends Item {
if (world instanceof ServerLevel worldserver) {
// CraftBukkit start
- if (Projectile.spawnProjectileFromRotation(ThrownEnderpearl::new, worldserver, itemstack, user, 0.0F, 1.5F, 1.0F).isRemoved()) {
+ // Paper start - PlayerLaunchProjectileEvent
+ final Projectile.Delayed<ThrownEnderpearl> thrownEnderpearl = Projectile.spawnProjectileFromRotationDelayed(ThrownEnderpearl::new, worldserver, itemstack, user, 0.0F, 1.5F, 1.0F);
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) thrownEnderpearl.projectile().getBukkitEntity());
+ if (event.callEvent() && thrownEnderpearl.attemptSpawn()) {
+ if (event.shouldConsume()) {
+ itemstack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
+ // Paper end - PlayerLaunchProjectileEvent
if (user instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
}
@@ -33,8 +46,7 @@ public class EnderpearlItem extends Item {
world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
// CraftBukkit end
- user.awardStat(Stats.ITEM_USED.get(this));
- itemstack.consume(1, user);
+ // Paper - PlayerLaunchProjectileEvent - moved up
return InteractionResult.SUCCESS;
}
}
diff --git a/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java b/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java
index b255e40277585928a767e5efd4b61708e13dab50..dfa3f9534159400e539ee61debedffb5f978aae8 100644
--- a/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java
+++ b/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java
@@ -21,22 +21,38 @@ public class ExperienceBottleItem extends Item implements ProjectileItem {
@Override
public InteractionResult use(Level world, Player user, InteractionHand hand) {
ItemStack itemStack = user.getItemInHand(hand);
- world.playSound(
- null,
- user.getX(),
- user.getY(),
- user.getZ(),
- SoundEvents.EXPERIENCE_BOTTLE_THROW,
- SoundSource.NEUTRAL,
- 0.5F,
- 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
- );
+ // Paper - PlayerLaunchProjectileEvent - moved down
if (world instanceof ServerLevel serverLevel) {
- Projectile.spawnProjectileFromRotation(ThrownExperienceBottle::new, serverLevel, itemStack, user, -20.0F, 0.7F, 1.0F);
+ // Paper start - PlayerLaunchProjectileEvent
+ final Projectile.Delayed<ThrownExperienceBottle> thrownExperienceBottle = Projectile.spawnProjectileFromRotationDelayed(ThrownExperienceBottle::new, serverLevel, itemStack, user, -20.0F, 0.7F, 1.0F);
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) thrownExperienceBottle.projectile().getBukkitEntity());
+ if (event.callEvent() && thrownExperienceBottle.attemptSpawn()) {
+ if (event.shouldConsume()) {
+ itemStack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound(
+ null,
+ user.getX(),
+ user.getY(),
+ user.getZ(),
+ SoundEvents.EXPERIENCE_BOTTLE_THROW,
+ SoundSource.NEUTRAL,
+ 0.5F,
+ 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
+ );
+ } else {
+ if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+ return InteractionResult.FAIL;
+ }
+ // Paper end - PlayerLaunchProjectileEvent
}
- user.awardStat(Stats.ITEM_USED.get(this));
- itemStack.consume(1, user);
+ // Paper - PlayerLaunchProjectileEvent - moved up
return InteractionResult.SUCCESS;
}
diff --git a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
index 400ad0fa1d07c8b120e3c3b5488dfa315aa2d23f..7e308b364227dedc2d05496f5e0c90573f4a53f7 100644
--- a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
+++ b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
@@ -33,7 +33,7 @@ public class FireworkRocketItem extends Item implements ProjectileItem {
ItemStack itemStack = context.getItemInHand();
Vec3 vec3 = context.getClickLocation();
Direction direction = context.getClickedFace();
- Projectile.spawnProjectile(
+ final Projectile.Delayed<FireworkRocketEntity> fireworkRocketEntity = Projectile.spawnProjectileDelayed( // Paper - PlayerLaunchProjectileEvent
new FireworkRocketEntity(
level,
context.getPlayer(),
@@ -45,7 +45,12 @@ public class FireworkRocketItem extends Item implements ProjectileItem {
serverLevel,
itemStack, f -> f.spawningEntity = context.getPlayer() == null ? null : context.getPlayer().getUUID() // Paper - firework api - assign spawning entity uuid
);
- itemStack.shrink(1);
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) context.getPlayer().getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Firework) fireworkRocketEntity.projectile().getBukkitEntity());
+ if (!event.callEvent() || fireworkRocketEntity.attemptSpawn()) return InteractionResult.PASS;
+ if (event.shouldConsume() && !context.getPlayer().hasInfiniteMaterials()) itemStack.shrink(1);
+ else if (context.getPlayer() instanceof net.minecraft.server.level.ServerPlayer) ((net.minecraft.server.level.ServerPlayer) context.getPlayer()).getBukkitEntity().updateInventory();
+ // Paper end - PlayerLaunchProjectileEvent
}
return InteractionResult.SUCCESS;
diff --git a/src/main/java/net/minecraft/world/item/LingeringPotionItem.java b/src/main/java/net/minecraft/world/item/LingeringPotionItem.java
index 7a5045469bc2d383ed087dcc094b6f97df4ec7ab..fa92a1346825f00a585503d0a0825711fe3f754e 100644
--- a/src/main/java/net/minecraft/world/item/LingeringPotionItem.java
+++ b/src/main/java/net/minecraft/world/item/LingeringPotionItem.java
@@ -24,6 +24,10 @@ public class LingeringPotionItem extends ThrowablePotionItem {
@Override
public InteractionResult use(Level world, Player user, InteractionHand hand) {
+ // Paper start - PlayerLaunchProjectileEvent
+ final InteractionResult wrapper = super.use(world, user, hand);
+ if (wrapper instanceof InteractionResult.Fail) return wrapper;
+ // Paper end - PlayerLaunchProjectileEvent
world.playSound(
null,
user.getX(),
@@ -34,6 +38,6 @@ public class LingeringPotionItem extends ThrowablePotionItem {
0.5F,
0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
);
- return super.use(world, user, hand);
+ return wrapper; // Paper - PlayerLaunchProjectileEvent
}
}
diff --git a/src/main/java/net/minecraft/world/item/SnowballItem.java b/src/main/java/net/minecraft/world/item/SnowballItem.java
index ada9bc42a788b5f472324a0765edf5766d729784..1e996276a80b34e353c6a7c7fee765c9db7123ea 100644
--- a/src/main/java/net/minecraft/world/item/SnowballItem.java
+++ b/src/main/java/net/minecraft/world/item/SnowballItem.java
@@ -26,17 +26,26 @@ public class SnowballItem extends Item implements ProjectileItem {
// CraftBukkit start - moved down
// world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
if (world instanceof ServerLevel worldserver) {
- if (Projectile.spawnProjectileFromRotation(Snowball::new, worldserver, itemstack, user, 0.0F, 1.5F, 1.0F).isAlive()) {
- itemstack.consume(1, user);
+ // Paper start - PlayerLaunchProjectileEvent
+ final Projectile.Delayed<Snowball> snowball = Projectile.spawnProjectileFromRotationDelayed(Snowball::new, worldserver, itemstack, user, 0.0F, 1.5F, 1.0F);
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entitysnowball.getBukkitEntity());
+ if (event.callEvent() && snowball.attemptSpawn()) {
+ user.awardStat(Stats.ITEM_USED.get(this));
+ if (event.shouldConsume()) {
+ itemstack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+ // Paper end - PlayerLaunchProjectileEvent
world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
- } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ } else { if (user instanceof net.minecraft.server.level.ServerPlayer) { // Paper - PlayerLaunchProjectileEvent - return fail
((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
- }
+ } return InteractionResult.FAIL; } // Paper - PlayerLaunchProjectileEvent - return fail
// CraftBukkit end
}
- user.awardStat(Stats.ITEM_USED.get(this));
+ // Paper - PlayerLaunchProjectileEvent - moved up
// itemstack.consume(1, entityhuman); // CraftBukkit - moved up
return InteractionResult.SUCCESS;
}
diff --git a/src/main/java/net/minecraft/world/item/SplashPotionItem.java b/src/main/java/net/minecraft/world/item/SplashPotionItem.java
index 6d622d276a632c9c29ab04a01fbe7adbf10c35cd..577e66a7ff64d9569ee2402ecc26b0aa1105fe9a 100644
--- a/src/main/java/net/minecraft/world/item/SplashPotionItem.java
+++ b/src/main/java/net/minecraft/world/item/SplashPotionItem.java
@@ -14,6 +14,10 @@ public class SplashPotionItem extends ThrowablePotionItem {
@Override
public InteractionResult use(Level world, Player user, InteractionHand hand) {
+ // Paper start - PlayerLaunchProjectileEvent
+ final InteractionResult wrapper = super.use(world, user, hand);
+ if (wrapper instanceof InteractionResult.Fail) return wrapper;
+ // Paper end - PlayerLaunchProjectileEvent
world.playSound(
null,
user.getX(),
@@ -24,6 +28,6 @@ public class SplashPotionItem extends ThrowablePotionItem {
0.5F,
0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
);
- return super.use(world, user, hand);
+ return wrapper; // Paper - PlayerLaunchProjectileEvent
}
}
diff --git a/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java b/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java
index e3eb733f18c23ae3fcc4c271843d285b217d1a7d..fa9d2ae44fcdd06f8f33cd14ffca422b20a01451 100644
--- a/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java
+++ b/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java
@@ -20,11 +20,28 @@ public class ThrowablePotionItem extends PotionItem implements ProjectileItem {
public InteractionResult use(Level world, Player user, InteractionHand hand) {
ItemStack itemStack = user.getItemInHand(hand);
if (world instanceof ServerLevel serverLevel) {
- Projectile.spawnProjectileFromRotation(ThrownPotion::new, serverLevel, itemStack, user, -20.0F, 0.5F, 1.0F);
+ // Paper start - PlayerLaunchProjectileEvent
+ final Projectile.Delayed<ThrownPotion> thrownPotion = Projectile.spawnProjectileFromRotationDelayed(ThrownPotion::new, serverLevel, itemStack, user, -20.0F, 0.5F, 1.0F);
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) thrownPotion.projectile().getBukkitEntity());
+ if (event.callEvent() && thrownPotion.attemptSpawn()) {
+ if (event.shouldConsume()) {
+ itemStack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
+ if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+ return InteractionResult.FAIL;
+ }
+ // Paper end - PlayerLaunchProjectileEvent
}
- user.awardStat(Stats.ITEM_USED.get(this));
- itemStack.consume(1, user);
+ // Paper - PlayerLaunchProjectileEvent - move up
return InteractionResult.SUCCESS;
}
diff --git a/src/main/java/net/minecraft/world/item/TridentItem.java b/src/main/java/net/minecraft/world/item/TridentItem.java
index 22aa715c4ef615c2c9d795cc2e11b7099d5167da..8b9a93ef71164cce8a616735b71d96d37e83b1a8 100644
--- a/src/main/java/net/minecraft/world/item/TridentItem.java
+++ b/src/main/java/net/minecraft/world/item/TridentItem.java
@@ -87,21 +87,26 @@ public class TridentItem extends Item implements ProjectileItem {
// itemstack.hurtWithoutBreaking(1, entityhuman); // CraftBukkit - moved down
if (f == 0.0F) {
- ThrownTrident entitythrowntrident = (ThrownTrident) Projectile.spawnProjectileFromRotation(ThrownTrident::new, worldserver, stack, entityhuman, 0.0F, 2.5F, 1.0F);
- // CraftBukkit start
- if (entitythrowntrident.isRemoved()) {
+ // Paper start - PlayerLaunchProjectileEvent
+ Projectile.Delayed<ThrownTrident> tridentDelayed = Projectile.spawnProjectileFromRotationDelayed(ThrownTrident::new, worldserver, stack, entityhuman, 0.0F, 2.5F, 1.0F);
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(stack), (org.bukkit.entity.Projectile) tridentDelayed.projectile().getBukkitEntity());
+ if (!event.callEvent() || !tridentDelayed.attemptSpawn()) {
+ // CraftBukkit start
+ // Paper end - PlayerLaunchProjectileEvent
if (entityhuman instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) entityhuman).getBukkitEntity().updateInventory();
}
return false;
}
- stack.hurtWithoutBreaking(1, entityhuman);
+ ThrownTrident entitythrowntrident = tridentDelayed.projectile(); // Paper - PlayerLaunchProjectileEvent
+ if (event.shouldConsume()) stack.hurtWithoutBreaking(1, entityhuman); // Paper - PlayerLaunchProjectileEvent
entitythrowntrident.pickupItemStack = stack.copy(); // SPIGOT-4511 update since damage call moved
// CraftBukkit end
if (entityhuman.hasInfiniteMaterials()) {
entitythrowntrident.pickup = AbstractArrow.Pickup.CREATIVE_ONLY;
- } else {
+ } else if (event.shouldConsume()) { // Paper - PlayerLaunchProjectileEvent
entityhuman.getInventory().removeItem(stack);
}
diff --git a/src/main/java/net/minecraft/world/item/WindChargeItem.java b/src/main/java/net/minecraft/world/item/WindChargeItem.java
index 79fdb78a4c3c7e324f0ed84a3dad9a3a80a6456a..0ce52d239b5bfb63e09cf5df679eee177f7bc5b0 100644
--- a/src/main/java/net/minecraft/world/item/WindChargeItem.java
+++ b/src/main/java/net/minecraft/world/item/WindChargeItem.java
@@ -25,7 +25,7 @@ public class WindChargeItem extends Item implements ProjectileItem {
public InteractionResult use(Level world, Player user, InteractionHand hand) {
ItemStack itemStack = user.getItemInHand(hand);
if (world instanceof ServerLevel serverLevel) {
- Projectile.spawnProjectileFromRotation(
+ final Projectile.Delayed<WindCharge> windCharge = Projectile.spawnProjectileFromRotationDelayed( // Paper - PlayerLaunchProjectileEvent
(world2, shooter, stack) -> new WindCharge(user, world, user.position().x(), user.getEyePosition().y(), user.position().z()),
serverLevel,
itemStack,
@@ -34,6 +34,21 @@ public class WindChargeItem extends Item implements ProjectileItem {
1.5F,
1.0F
);
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) windCharge.projectile().getBukkitEntity());
+ if (!event.callEvent() || !windCharge.attemptSpawn()) {
+ user.containerMenu.sendAllDataToRemote();
+ if (user instanceof net.minecraft.server.level.ServerPlayer player) {
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundCooldownPacket(user.getCooldowns().getCooldownGroup(itemStack), 0)); // prevent visual desync of cooldown on the slot
+ }
+ return InteractionResult.FAIL;
+ }
+
+ user.awardStat(Stats.ITEM_USED.get(this));
+ if (event.shouldConsume()) itemStack.consume(1, user);
+ else if (!user.hasInfiniteMaterials()) {
+ user.containerMenu.sendAllDataToRemote();
+ }
+ // Paper end - PlayerLaunchProjectileEvent
}
world.playSound(
@@ -46,8 +61,6 @@ public class WindChargeItem extends Item implements ProjectileItem {
0.5F,
0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
);
- user.awardStat(Stats.ITEM_USED.get(this));
- itemStack.consume(1, user);
return InteractionResult.SUCCESS;
}

Datei anzeigen

@ -1,33 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 21 Jul 2018 01:59:59 -0500
Subject: [PATCH] PlayerElytraBoostEvent
diff --git a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
index 38b33eb92d21d0099285a304c6e064bbf56db4eb..16da60b7ecf2e0d4a49804dfa1ad47d4ae672571 100644
--- a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
+++ b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
@@ -57,9 +57,19 @@ public class FireworkRocketItem extends Item implements ProjectileItem {
if (!world.isClientSide) {
FireworkRocketEntity fireworkRocketEntity = new FireworkRocketEntity(world, itemStack, user);
fireworkRocketEntity.spawningEntity = user.getUUID(); // Paper
- world.addFreshEntity(fireworkRocketEntity);
- itemStack.consume(1, user);
- user.awardStat(Stats.ITEM_USED.get(this));
+ // Paper start - PlayerElytraBoostEvent
+ com.destroystokyo.paper.event.player.PlayerElytraBoostEvent event = new com.destroystokyo.paper.event.player.PlayerElytraBoostEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Firework) fireworkRocketEntity.getBukkitEntity(), org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(hand));
+ if (event.callEvent() && world.addFreshEntity(fireworkRocketEntity)) {
+ user.awardStat(Stats.ITEM_USED.get(this));
+ if (event.shouldConsume() && !user.hasInfiniteMaterials()) {
+ itemStack.shrink(1);
+ } else ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ // Paper end - PlayerElytraBoostEvent
+ }
+
+ // user.awardStat(Stats.ITEM_USED.get(this)); // Paper - PlayerElytraBoostEvent; move up
}
return InteractionResultHolder.sidedSuccess(user.getItemInHand(hand), world.isClientSide());

Datei anzeigen

@ -1,363 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 21 Jul 2018 03:11:03 -0500
Subject: [PATCH] PlayerLaunchProjectileEvent
diff --git a/src/main/java/net/minecraft/world/item/EggItem.java b/src/main/java/net/minecraft/world/item/EggItem.java
index be7d1bfb13cf0afb80ba98f3b56602bccebeab64..4ebd634cff286b10868e26eeb3ecf34abdcab22e 100644
--- a/src/main/java/net/minecraft/world/item/EggItem.java
+++ b/src/main/java/net/minecraft/world/item/EggItem.java
@@ -28,19 +28,31 @@ public class EggItem extends Item implements ProjectileItem {
entityegg.setItem(itemstack);
entityegg.shootFromRotation(user, user.getXRot(), user.getYRot(), 0.0F, 1.5F, 1.0F);
- // CraftBukkit start
- if (!world.addFreshEntity(entityegg)) {
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entityegg.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(entityegg)) {
+ if (event.shouldConsume()) {
+ itemstack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), net.minecraft.sounds.SoundEvents.EGG_THROW, net.minecraft.sounds.SoundSource.PLAYERS, 0.5F, 0.4F / (net.minecraft.world.entity.Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
if (user instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
}
return InteractionResultHolder.fail(itemstack);
}
- // CraftBukkit end
+ // Paper end - PlayerLaunchProjectileEvent
}
world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.EGG_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
+ /* // Paper start - PlayerLaunchProjectileEvent; moved up
user.awardStat(Stats.ITEM_USED.get(this));
itemstack.consume(1, user);
+ */ // Paper end - PlayerLaunchProjectileEvent
return InteractionResultHolder.sidedSuccess(itemstack, world.isClientSide());
}
diff --git a/src/main/java/net/minecraft/world/item/EnderpearlItem.java b/src/main/java/net/minecraft/world/item/EnderpearlItem.java
index 48048204b619dd515253c8ffb05a0f7105ef7718..20a91d798d31a71b3c05efa2cc5bda55494e26cc 100644
--- a/src/main/java/net/minecraft/world/item/EnderpearlItem.java
+++ b/src/main/java/net/minecraft/world/item/EnderpearlItem.java
@@ -25,7 +25,20 @@ public class EnderpearlItem extends Item {
entityenderpearl.setItem(itemstack);
entityenderpearl.shootFromRotation(user, user.getXRot(), user.getYRot(), 0.0F, 1.5F, 1.0F);
- if (!world.addFreshEntity(entityenderpearl)) {
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entityenderpearl.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(entityenderpearl)) {
+ if (event.shouldConsume()) {
+ itemstack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (net.minecraft.world.entity.Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ user.awardStat(Stats.ITEM_USED.get(this));
+ user.getCooldowns().addCooldown(this, 20);
+ } else {
+ // Paper end - PlayerLaunchProjectileEvent
if (user instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
}
@@ -33,12 +46,14 @@ public class EnderpearlItem extends Item {
}
}
+ /* // Paper start - PlayerLaunchProjectileEvent; moved up
world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
user.getCooldowns().addCooldown(this, 20);
// CraftBukkit end
user.awardStat(Stats.ITEM_USED.get(this));
itemstack.consume(1, user);
+ */ // Paper end - PlayerLaunchProjectileEvent; moved up
return InteractionResultHolder.sidedSuccess(itemstack, world.isClientSide());
}
}
diff --git a/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java b/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java
index 686f0fd87e06fa7552d66fd3e38a3e059c22f180..7448309b6dca619b6366aa55fe3a395a830ffbdd 100644
--- a/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java
+++ b/src/main/java/net/minecraft/world/item/ExperienceBottleItem.java
@@ -20,25 +20,44 @@ public class ExperienceBottleItem extends Item implements ProjectileItem {
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
ItemStack itemStack = user.getItemInHand(hand);
- world.playSound(
- null,
- user.getX(),
- user.getY(),
- user.getZ(),
- SoundEvents.EXPERIENCE_BOTTLE_THROW,
- SoundSource.NEUTRAL,
- 0.5F,
- 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
- );
+ // Paper - PlayerLaunchProjectileEvent; moved down
if (!world.isClientSide) {
ThrownExperienceBottle thrownExperienceBottle = new ThrownExperienceBottle(world, user);
thrownExperienceBottle.setItem(itemStack);
thrownExperienceBottle.shootFromRotation(user, user.getXRot(), user.getYRot(), -20.0F, 0.7F, 1.0F);
- world.addFreshEntity(thrownExperienceBottle);
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) thrownExperienceBottle.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(thrownExperienceBottle)) {
+ if (event.shouldConsume()) {
+ itemStack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound(
+ null,
+ user.getX(),
+ user.getY(),
+ user.getZ(),
+ SoundEvents.EXPERIENCE_BOTTLE_THROW,
+ SoundSource.NEUTRAL,
+ 0.5F,
+ 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
+ );
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
+ if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+ return InteractionResultHolder.fail(itemStack);
+ }
+ // Paper end - PlayerLaunchProjectileEvent
}
+ /* // Paper start - PlayerLaunchProjectileEvent; moved up
user.awardStat(Stats.ITEM_USED.get(this));
itemStack.consume(1, user);
+ */ // Paper end - PlayerLaunchProjectileEvent
return InteractionResultHolder.sidedSuccess(itemStack, world.isClientSide());
}
diff --git a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
index 16da60b7ecf2e0d4a49804dfa1ad47d4ae672571..218f2f085309f04438f8b07bc41cf242583db2dc 100644
--- a/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
+++ b/src/main/java/net/minecraft/world/item/FireworkRocketItem.java
@@ -43,8 +43,12 @@ public class FireworkRocketItem extends Item implements ProjectileItem {
itemStack
);
fireworkRocketEntity.spawningEntity = context.getPlayer() == null ? null : context.getPlayer().getUUID(); // Paper
- level.addFreshEntity(fireworkRocketEntity);
- itemStack.shrink(1);
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) context.getPlayer().getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Firework) fireworkRocketEntity.getBukkitEntity());
+ if (!event.callEvent() || !level.addFreshEntity(fireworkRocketEntity)) return InteractionResult.PASS;
+ if (event.shouldConsume() && !context.getPlayer().getAbilities().instabuild) itemStack.shrink(1);
+ else if (context.getPlayer() instanceof net.minecraft.server.level.ServerPlayer) ((net.minecraft.server.level.ServerPlayer) context.getPlayer()).getBukkitEntity().updateInventory();
+ // Paper end - PlayerLaunchProjectileEvent
}
return InteractionResult.sidedSuccess(level.isClientSide);
diff --git a/src/main/java/net/minecraft/world/item/LingeringPotionItem.java b/src/main/java/net/minecraft/world/item/LingeringPotionItem.java
index b94888d359ec92bf7ef77b0610f41ba75185a26e..c9b511cc4f2499ca13e3cd8f1cdabdc225f66b9c 100644
--- a/src/main/java/net/minecraft/world/item/LingeringPotionItem.java
+++ b/src/main/java/net/minecraft/world/item/LingeringPotionItem.java
@@ -24,6 +24,10 @@ public class LingeringPotionItem extends ThrowablePotionItem {
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
+ // Paper start - PlayerLaunchProjectileEvent
+ InteractionResultHolder<ItemStack> wrapper = super.use(world, user, hand);
+ if (wrapper.getResult() != net.minecraft.world.InteractionResult.FAIL) {
+ // Paper end - PlayerLaunchProjectileEvent
world.playSound(
null,
user.getX(),
@@ -34,6 +38,9 @@ public class LingeringPotionItem extends ThrowablePotionItem {
0.5F,
0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
);
- return super.use(world, user, hand);
+ // Paper start - PlayerLaunchProjectileEvent
+ }
+ return wrapper;
+ // Paper end - PlayerLaunchProjectileEvent
}
}
diff --git a/src/main/java/net/minecraft/world/item/SnowballItem.java b/src/main/java/net/minecraft/world/item/SnowballItem.java
index 2ae40936b31012fab0c7c42a7dea13b01ec6068f..32b170551a2f5bdc88d29f4d03750bfe3974e71b 100644
--- a/src/main/java/net/minecraft/world/item/SnowballItem.java
+++ b/src/main/java/net/minecraft/world/item/SnowballItem.java
@@ -29,17 +29,26 @@ public class SnowballItem extends Item implements ProjectileItem {
entitysnowball.setItem(itemstack);
entitysnowball.shootFromRotation(user, user.getXRot(), user.getYRot(), 0.0F, 1.5F, 1.0F);
- if (world.addFreshEntity(entitysnowball)) {
- itemstack.consume(1, user);
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entitysnowball.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(entitysnowball)) {
+ user.awardStat(Stats.ITEM_USED.get(this));
+ if (event.shouldConsume()) {
+ // Paper end - PlayerLaunchProjectileEvent
+ itemstack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) { // Paper - PlayerLaunchProjectileEvent
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory(); // Paper - PlayerLaunchProjectileEvent
+ }
world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
- } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
- ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ } else { // Paper - PlayerLaunchProjectileEvent
+ if (user instanceof net.minecraft.server.level.ServerPlayer) ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory(); // Paper - PlayerLaunchProjectileEvent
+ return InteractionResultHolder.fail(itemstack); // Paper - PlayerLaunchProjectileEvent
}
}
// CraftBukkit end
- user.awardStat(Stats.ITEM_USED.get(this));
+ // user.awardStat(Stats.ITEM_USED.get(this)); // Paper - PlayerLaunchProjectileEvent; moved up
// itemstack.consume(1, entityhuman); // CraftBukkit - moved up
return InteractionResultHolder.sidedSuccess(itemstack, world.isClientSide());
}
diff --git a/src/main/java/net/minecraft/world/item/SplashPotionItem.java b/src/main/java/net/minecraft/world/item/SplashPotionItem.java
index 935c34ba7eb14348becdd3ac0c29766abf7ca614..73bac60b3bf6d20d415a8250d0426251c0c3265b 100644
--- a/src/main/java/net/minecraft/world/item/SplashPotionItem.java
+++ b/src/main/java/net/minecraft/world/item/SplashPotionItem.java
@@ -14,6 +14,10 @@ public class SplashPotionItem extends ThrowablePotionItem {
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
+ // Paper start - PlayerLaunchProjectileEvent
+ InteractionResultHolder<ItemStack> wrapper = super.use(world, user, hand);
+ if (wrapper.getResult() != net.minecraft.world.InteractionResult.FAIL) {
+ // Paper end - PlayerLaunchProjectileEvent
world.playSound(
null,
user.getX(),
@@ -24,6 +28,9 @@ public class SplashPotionItem extends ThrowablePotionItem {
0.5F,
0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
);
- return super.use(world, user, hand);
+ // Paper start - PlayerLaunchProjectileEvent
+ }
+ return wrapper;
+ // Paper end - PlayerLaunchProjectileEvent
}
}
diff --git a/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java b/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java
index 12795451393e48f5c9ab4b1dfd9369e1ee6e0367..369955746f4b51f69fa01103e3771dd74fc6c8f0 100644
--- a/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java
+++ b/src/main/java/net/minecraft/world/item/ThrowablePotionItem.java
@@ -22,11 +22,29 @@ public class ThrowablePotionItem extends PotionItem implements ProjectileItem {
ThrownPotion thrownPotion = new ThrownPotion(world, user);
thrownPotion.setItem(itemStack);
thrownPotion.shootFromRotation(user, user.getXRot(), user.getYRot(), -20.0F, 0.5F, 1.0F);
- world.addFreshEntity(thrownPotion);
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) thrownPotion.getBukkitEntity());
+ if (event.callEvent() && world.addFreshEntity(thrownPotion)) {
+ if (event.shouldConsume()) {
+ itemStack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
+ if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+ return InteractionResultHolder.fail(itemStack);
+ }
+ // Paper end - PlayerLaunchProjectileEvent
}
+ /* // Paper start - PlayerLaunchProjectileEvent; moved up
user.awardStat(Stats.ITEM_USED.get(this));
itemStack.consume(1, user);
+ */ // Paper end
return InteractionResultHolder.sidedSuccess(itemStack, world.isClientSide());
}
diff --git a/src/main/java/net/minecraft/world/item/TridentItem.java b/src/main/java/net/minecraft/world/item/TridentItem.java
index 2d34f206b4b02d5f2ee35101233afc6b4f58a579..f1b2d388a1a40a1d909a2e726f32d6c15e1eb0eb 100644
--- a/src/main/java/net/minecraft/world/item/TridentItem.java
+++ b/src/main/java/net/minecraft/world/item/TridentItem.java
@@ -87,19 +87,24 @@ public class TridentItem extends Item implements ProjectileItem {
}
// CraftBukkit start
- if (!world.addFreshEntity(entitythrowntrident)) {
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(stack), (org.bukkit.entity.Projectile) entitythrowntrident.getBukkitEntity());
+ if (!event.callEvent() || !world.addFreshEntity(entitythrowntrident)) {
+ // Paper end - PlayerLaunchProjectileEvent
if (entityhuman instanceof net.minecraft.server.level.ServerPlayer) {
((net.minecraft.server.level.ServerPlayer) entityhuman).getBukkitEntity().updateInventory();
}
return;
}
+ if (event.shouldConsume()) { // Paper - PlayerLaunchProjectileEvent
stack.hurtAndBreak(1, entityhuman, LivingEntity.getSlotForHand(user.getUsedItemHand()));
+ } // Paper - PlayerLaunchProjectileEvent
entitythrowntrident.pickupItemStack = stack.copy(); // SPIGOT-4511 update since damage call moved
// CraftBukkit end
world.playSound((Player) null, (Entity) entitythrowntrident, (SoundEvent) holder.value(), SoundSource.PLAYERS, 1.0F, 1.0F);
- if (!entityhuman.hasInfiniteMaterials()) {
+ if (event.shouldConsume() && !entityhuman.hasInfiniteMaterials()) { // Paper - PlayerLaunchProjectileEvent
entityhuman.getInventory().removeItem(stack);
}
// CraftBukkit start - SPIGOT-5458 also need in this branch :(
diff --git a/src/main/java/net/minecraft/world/item/WindChargeItem.java b/src/main/java/net/minecraft/world/item/WindChargeItem.java
index 6222e867bb959fab05bcd8f2114ab00b26847c3e..eed0d754e9a3c7c94614e0fd54651500e0612ea8 100644
--- a/src/main/java/net/minecraft/world/item/WindChargeItem.java
+++ b/src/main/java/net/minecraft/world/item/WindChargeItem.java
@@ -24,10 +24,26 @@ public class WindChargeItem extends Item implements ProjectileItem {
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
+ ItemStack itemStack = user.getItemInHand(hand); // Paper - PlayerLaunchProjectileEvent; moved from below
+ boolean shouldConsume = true; // Paper - PlayerLaunchProjectileEvent
if (!world.isClientSide()) {
WindCharge windCharge = new WindCharge(user, world, user.position().x(), user.getEyePosition().y(), user.position().z());
windCharge.shootFromRotation(user, user.getXRot(), user.getYRot(), 0.0F, 1.5F, 1.0F);
- world.addFreshEntity(windCharge);
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) windCharge.getBukkitEntity());
+ if (!event.callEvent() || !world.addFreshEntity(windCharge)) {
+ user.containerMenu.sendAllDataToRemote();
+ if (user instanceof net.minecraft.server.level.ServerPlayer player) {
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundCooldownPacket(this, 0)); // prevent visual desync of cooldown on the slot
+ }
+ return InteractionResultHolder.fail(itemStack);
+ }
+
+ shouldConsume = event.shouldConsume();
+ if (!shouldConsume && !user.hasInfiniteMaterials()) {
+ user.containerMenu.sendAllDataToRemote();
+ }
+ // Paper end - PlayerLaunchProjectileEvent
}
world.playSound(
@@ -40,10 +56,9 @@ public class WindChargeItem extends Item implements ProjectileItem {
0.5F,
0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)
);
- ItemStack itemStack = user.getItemInHand(hand);
user.getCooldowns().addCooldown(this, 10);
user.awardStat(Stats.ITEM_USED.get(this));
- itemStack.consume(1, user);
+ if (shouldConsume) itemStack.consume(1, user); // Paper - PlayerLaunchProjectileEvent
return InteractionResultHolder.sidedSuccess(itemStack, world.isClientSide());
}