3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-24 07:10:10 +01:00
Paper/nms-patches/BlockSweetBerryBush.patch

53 Zeilen
2.7 KiB
Diff

2019-04-23 04:00:00 +02:00
--- a/net/minecraft/server/BlockSweetBerryBush.java
+++ b/net/minecraft/server/BlockSweetBerryBush.java
2020-07-03 07:07:15 +02:00
@@ -1,6 +1,13 @@
2019-04-23 04:00:00 +02:00
package net.minecraft.server;
import java.util.Random;
+// CraftBukkit start
2020-07-03 07:07:15 +02:00
+import java.util.Collections;
2019-04-23 04:00:00 +02:00
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2020-07-03 07:07:15 +02:00
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerHarvestBlockEvent;
2019-04-23 04:00:00 +02:00
+// CraftBukkit end
public class BlockSweetBerryBush extends BlockPlant implements IBlockFragilePlantElement {
2020-07-03 07:07:15 +02:00
@@ -28,7 +35,7 @@
2019-04-23 04:00:00 +02:00
int i = (Integer) iblockdata.get(BlockSweetBerryBush.a);
2019-12-10 23:00:00 +01:00
if (i < 3 && random.nextInt(5) == 0 && worldserver.getLightLevel(blockposition.up(), 0) >= 9) {
- worldserver.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockSweetBerryBush.a, i + 1), 2);
+ CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, (IBlockData) iblockdata.set(BlockSweetBerryBush.a, i + 1), 2); // CraftBukkit
2019-04-23 04:00:00 +02:00
}
}
2020-07-03 07:07:15 +02:00
@@ -42,7 +49,9 @@
2020-06-25 02:00:00 +02:00
double d1 = Math.abs(entity.locZ() - entity.F);
2019-04-23 04:00:00 +02:00
if (d0 >= 0.003000000026077032D || d1 >= 0.003000000026077032D) {
+ CraftEventFactory.blockDamage = CraftBlock.at(world, blockposition); // CraftBukkit
entity.damageEntity(DamageSource.SWEET_BERRY_BUSH, 1.0F);
+ CraftEventFactory.blockDamage = null; // CraftBukkit
}
}
2020-07-03 07:07:15 +02:00
@@ -59,7 +68,15 @@
} else if (i > 1) {
int j = 1 + world.random.nextInt(2);
- a(world, blockposition, new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0)));
+ // CraftBukkit start
+ PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(world, blockposition, entityhuman, Collections.singletonList(new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0))));
+ if (event.isCancelled()) {
+ return EnumInteractionResult.SUCCESS; // We need to return a success either way, because making it PASS or FAIL will result in a bug where cancelling while harvesting w/ block in hand places block
+ }
+ for (org.bukkit.inventory.ItemStack itemStack : event.getItemsHarvested()) {
+ a(world, blockposition, CraftItemStack.asNMSCopy(itemStack));
+ }
+ // CraftBukkit end
world.playSound((EntityHuman) null, blockposition, SoundEffects.ITEM_SWEET_BERRIES_PICK_FROM_BUSH, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F);
world.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockSweetBerryBush.a, 1), 2);
return EnumInteractionResult.a(world.isClientSide);