9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2026-01-03 22:16:22 +00:00
Files
DivineMC/divinemc-server/minecraft-patches/features/0038-Paper-PR-Add-FillBottleEvents-for-player-and-dispens.patch
2025-04-24 19:47:15 +03:00

147 lines
11 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 23 Mar 2025 16:47:24 +0300
Subject: [PATCH] Paper PR: Add FillBottleEvents for player and dispenser
diff --git a/net/minecraft/core/cauldron/CauldronInteraction.java b/net/minecraft/core/cauldron/CauldronInteraction.java
index a1ce1548bb008f1854baa4c5d6cd963c3a3f7a36..12f3875ed5638ca25787d5307de0b22cf0b63b64 100644
--- a/net/minecraft/core/cauldron/CauldronInteraction.java
+++ b/net/minecraft/core/cauldron/CauldronInteraction.java
@@ -63,7 +63,12 @@ public interface CauldronInteraction {
}
// CraftBukkit end
Item item = stack.getItem();
- player.setItemInHand(hand, ItemUtils.createFilledResult(stack, player, new ItemStack(Items.GLASS_BOTTLE)));
+ // DivineMC start - Paper PR: Add FillBottleEvents for player and dispenser
+ final io.papermc.paper.event.player.PlayerFillBottleEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerFillBottleEvent(player, hand, stack, ItemUtils.createFilledResult(stack, player, new ItemStack(Items.GLASS_BOTTLE)));
+ if (event.isCancelled()) {
+ return InteractionResult.PASS;
+ }
+ // DivineMC end - Paper PR: Add FillBottleEvents for player and dispenser
player.awardStat(Stats.USE_CAULDRON);
player.awardStat(Stats.ITEM_USED.get(item));
// level.setBlockAndUpdate(pos, Blocks.WATER_CAULDRON.defaultBlockState()); // CraftBukkit
diff --git a/net/minecraft/core/dispenser/DispenseItemBehavior.java b/net/minecraft/core/dispenser/DispenseItemBehavior.java
index 582e012222123e5001c34153f2ee1ab1d08935fd..ac27ff24f018d8798921c5152e679ceed1e88d8d 100644
--- a/net/minecraft/core/dispenser/DispenseItemBehavior.java
+++ b/net/minecraft/core/dispenser/DispenseItemBehavior.java
@@ -569,13 +569,25 @@ public interface DispenseItemBehavior {
blockStateBase -> blockStateBase.hasProperty(BeehiveBlock.HONEY_LEVEL) && blockStateBase.getBlock() instanceof BeehiveBlock
)
&& blockState.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
+ // DivineMC start - Paper PR: Add FillBottleEvents for player and dispenser
+ final io.papermc.paper.event.block.BlockFillBottleEvent bottleEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFillBottleEvent(serverLevel, blockSource.pos(), item, new ItemStack(Items.HONEY_BOTTLE));
+ if (bottleEvent.isCancelled()) {
+ return item;
+ }
+ // DivineMC end - Paper PR: Add FillBottleEvents for player and dispenser
((BeehiveBlock)blockState.getBlock())
.releaseBeesAndResetHoneyLevel(serverLevel, blockState, blockPos, null, BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED);
this.setSuccess(true);
- return this.takeLiquid(blockSource, item, new ItemStack(Items.HONEY_BOTTLE));
+ return this.takeLiquid(blockSource, item, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(bottleEvent.getResultItem())); // DivineMC - Paper PR: Add FillBottleEvents for player and dispenser
} else if (serverLevel.getFluidState(blockPos).is(FluidTags.WATER)) {
+ // DivineMC start - Paper PR: Add FillBottleEvents for player and dispenser
+ final io.papermc.paper.event.block.BlockFillBottleEvent bottleEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFillBottleEvent(serverLevel, blockSource.pos(), item, PotionContents.createItemStack(Items.POTION, Potions.WATER));
+ if (bottleEvent.isCancelled()) {
+ return item;
+ }
+ // DivineMC end - Paper PR: Add FillBottleEvents for player and dispenser
this.setSuccess(true);
- return this.takeLiquid(blockSource, item, PotionContents.createItemStack(Items.POTION, Potions.WATER));
+ return this.takeLiquid(blockSource, item, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(bottleEvent.getResultItem())); // DivineMC - Paper PR: Add FillBottleEvents for player and dispenser
} else {
return super.execute(blockSource, item);
}
diff --git a/net/minecraft/world/item/BottleItem.java b/net/minecraft/world/item/BottleItem.java
index 105f9166297de2bfa6bdcfa9f6a0ffb00c0242ac..111f43fc5c74577f8f3067a4f84be7a6f96fdfb2 100644
--- a/net/minecraft/world/item/BottleItem.java
+++ b/net/minecraft/world/item/BottleItem.java
@@ -35,6 +35,18 @@ public class BottleItem extends Item {
);
ItemStack itemInHand = player.getItemInHand(hand);
if (!entitiesOfClass.isEmpty()) {
+ // DivineMC start - Paper PR: Add FillBottleEvents for player and dispenser
+ final io.papermc.paper.event.player.PlayerFillBottleEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerFillBottleEvent(player, hand, itemInHand, new ItemStack(Items.DRAGON_BREATH));
+ //noinspection DuplicatedCode
+ if (event.isCancelled()) {
+ player.containerMenu.sendAllDataToRemote();
+ return InteractionResult.PASS;
+ }
+ final ItemStack resultItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getResultItem());
+ if (resultItem.is(itemInHand.getItem())) {
+ player.containerMenu.sendAllDataToRemote();
+ }
+ // DivineMC end - Paper PR: Add FillBottleEvents for player and dispenser
AreaEffectCloud areaEffectCloud = entitiesOfClass.get(0);
areaEffectCloud.setRadius(areaEffectCloud.getRadius() - 0.5F);
level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.BOTTLE_FILL_DRAGONBREATH, SoundSource.NEUTRAL, 1.0F, 1.0F);
@@ -43,7 +55,7 @@ public class BottleItem extends Item {
CriteriaTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(serverPlayer, itemInHand, areaEffectCloud);
}
- return InteractionResult.SUCCESS.heldItemTransformedTo(this.turnBottleIntoItem(itemInHand, player, new ItemStack(Items.DRAGON_BREATH)));
+ return InteractionResult.SUCCESS.heldItemTransformedTo(this.turnBottleIntoItem(itemInHand, player, resultItem)); // DivineMC - Paper PR: Add FillBottleEvents for player and dispenser
} else {
BlockHitResult playerPovHitResult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.SOURCE_ONLY);
if (playerPovHitResult.getType() == HitResult.Type.MISS) {
@@ -56,10 +68,22 @@ public class BottleItem extends Item {
}
if (level.getFluidState(blockPos).is(FluidTags.WATER)) {
+ // DivineMC start - Paper PR: Add FillBottleEvents for player and dispenser
+ final io.papermc.paper.event.player.PlayerFillBottleEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerFillBottleEvent(player, hand, itemInHand, PotionContents.createItemStack(Items.POTION, Potions.WATER));
+ //noinspection DuplicatedCode
+ if (event.isCancelled()) {
+ player.containerMenu.sendAllDataToRemote();
+ return InteractionResult.PASS;
+ }
+ final ItemStack resultItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getResultItem());
+ if (resultItem.is(itemInHand.getItem())) {
+ player.containerMenu.sendAllDataToRemote();
+ }
+ // DivineMC end - Paper PR: Add FillBottleEvents for player and dispenser
level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BOTTLE_FILL, SoundSource.NEUTRAL, 1.0F, 1.0F);
level.gameEvent(player, GameEvent.FLUID_PICKUP, blockPos);
return InteractionResult.SUCCESS
- .heldItemTransformedTo(this.turnBottleIntoItem(itemInHand, player, PotionContents.createItemStack(Items.POTION, Potions.WATER)));
+ .heldItemTransformedTo(this.turnBottleIntoItem(itemInHand, player, resultItem)); // DivineMC - Paper PR: Add FillBottleEvents for player and dispenser
}
}
diff --git a/net/minecraft/world/level/block/BeehiveBlock.java b/net/minecraft/world/level/block/BeehiveBlock.java
index 3cec4c5a40c569d848bbf503501d8c8d38ecf3ce..1e92dbb04445596e3adee0ef5f1db47b7cec908e 100644
--- a/net/minecraft/world/level/block/BeehiveBlock.java
+++ b/net/minecraft/world/level/block/BeehiveBlock.java
@@ -155,12 +155,26 @@ public class BeehiveBlock extends BaseEntityBlock {
flag = true;
level.gameEvent(player, GameEvent.SHEAR, pos);
} else if (stack.is(Items.GLASS_BOTTLE)) {
+ // DivineMC start - Paper PR: Add FillBottleEvents for player and dispenser
+ final io.papermc.paper.event.player.PlayerFillBottleEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerFillBottleEvent(player, hand, stack, new ItemStack(Items.HONEY_BOTTLE));
+ //noinspection DuplicatedCode
+ if (event.isCancelled()) {
+ player.containerMenu.sendAllDataToRemote();
+ return InteractionResult.PASS;
+ }
+ final ItemStack resultItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getResultItem());
+ if (resultItem.is(stack.getItem())) {
+ player.containerMenu.sendAllDataToRemote();
+ }
+ // DivineMC end - Paper PR: Add FillBottleEvents for player and dispenser
stack.shrink(1);
level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BOTTLE_FILL, SoundSource.BLOCKS, 1.0F, 1.0F);
if (stack.isEmpty()) {
- player.setItemInHand(hand, new ItemStack(Items.HONEY_BOTTLE));
- } else if (!player.getInventory().add(new ItemStack(Items.HONEY_BOTTLE))) {
- player.drop(new ItemStack(Items.HONEY_BOTTLE), false);
+ // DivineMC start - Paper PR: Add FillBottleEvents for player and dispenser
+ player.setItemInHand(hand, resultItem);
+ } else if (!player.getInventory().add(resultItem)) {
+ player.drop(resultItem, false);
+ // DivineMC end - Paper PR: Add FillBottleEvents for player and dispenser
}
flag = true;