mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 10:17:38 +01:00
SPIGOT-2490: Villager farming event
By: md_5 <git@md-5.net>
This commit is contained in:
parent
6558543222
commit
9797cf7e43
@ -56,7 +56,7 @@
|
|||||||
this.playEffect(world, blockposition);
|
this.playEffect(world, blockposition);
|
||||||
if (this == Blocks.REDSTONE_ORE) {
|
if (this == Blocks.REDSTONE_ORE) {
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition.getX(), blockposition.getY(), blockposition.getZ(), Blocks.LIT_REDSTONE_ORE, 0).isCancelled()) {
|
+ if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.LIT_REDSTONE_ORE, 0).isCancelled()) {
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition.getX(), blockposition.getY(), blockposition.getZ(), Blocks.DIRT, 0).isCancelled()) {
|
+ if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.DIRT, 0).isCancelled()) {
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
public void a(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) {
|
public void a(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) {
|
||||||
super.a(world, blockposition, iblockdata, entity);
|
super.a(world, blockposition, iblockdata, entity);
|
||||||
- if (entity instanceof EntityBoat) {
|
- if (entity instanceof EntityBoat) {
|
||||||
+ if (entity instanceof EntityBoat && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition.getX(), blockposition.getY(), blockposition.getZ(), Blocks.AIR, 0).isCancelled()) { // CraftBukkit
|
+ if (entity instanceof EntityBoat && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR, 0).isCancelled()) { // CraftBukkit
|
||||||
world.setAir(new BlockPosition(blockposition), true);
|
world.setAir(new BlockPosition(blockposition), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
if (iblockdata2 != null && this.a(world, blockposition, iblockdata2.getBlock(), iblockdata, iblockdata1)) {
|
if (iblockdata2 != null && this.a(world, blockposition, iblockdata2.getBlock(), iblockdata, iblockdata1)) {
|
||||||
+ // CraftBukkit start - Place event
|
+ // CraftBukkit start - Place event
|
||||||
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.a, blockposition.getX(), blockposition.getY(), blockposition.getZ(), this.a.getCarried().getBlock(), this.a.getCarried().getBlock().toLegacyData(this.a.getCarried())).isCancelled()) {
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.a, blockposition, this.a.getCarried().getBlock(), this.a.getCarried().getBlock().toLegacyData(this.a.getCarried())).isCancelled()) {
|
||||||
world.setTypeAndData(blockposition, iblockdata2, 3);
|
world.setTypeAndData(blockposition, iblockdata2, 3);
|
||||||
this.a.setCarried((IBlockData) null);
|
this.a.setCarried((IBlockData) null);
|
||||||
+ }
|
+ }
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
if (this.ticksLived++ == 0) {
|
if (this.ticksLived++ == 0) {
|
||||||
blockposition = new BlockPosition(this);
|
blockposition = new BlockPosition(this);
|
||||||
- if (this.world.getType(blockposition).getBlock() == block) {
|
- if (this.world.getType(blockposition).getBlock() == block) {
|
||||||
+ if (this.world.getType(blockposition).getBlock() == block && !CraftEventFactory.callEntityChangeBlockEvent(this, blockposition.getX(), blockposition.getY(), blockposition.getZ(), Blocks.AIR, 0).isCancelled()) {
|
+ if (this.world.getType(blockposition).getBlock() == block && !CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR, 0).isCancelled()) {
|
||||||
this.world.setAir(blockposition);
|
this.world.setAir(blockposition);
|
||||||
} else if (!this.world.isClientSide) {
|
} else if (!this.world.isClientSide) {
|
||||||
this.die();
|
this.die();
|
||||||
@ -34,7 +34,7 @@
|
|||||||
- if (this.world.a(block, blockposition, true, EnumDirection.UP, (Entity) null, (ItemStack) null) && !BlockFalling.i(this.world.getType(blockposition.down())) && this.world.setTypeAndData(blockposition, this.block, 3)) {
|
- if (this.world.a(block, blockposition, true, EnumDirection.UP, (Entity) null, (ItemStack) null) && !BlockFalling.i(this.world.getType(blockposition.down())) && this.world.setTypeAndData(blockposition, this.block, 3)) {
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (this.world.a(block, blockposition, true, EnumDirection.UP, (Entity) null, (ItemStack) null) && !BlockFalling.i(this.world.getType(blockposition.down()))) {
|
+ if (this.world.a(block, blockposition, true, EnumDirection.UP, (Entity) null, (ItemStack) null) && !BlockFalling.i(this.world.getType(blockposition.down()))) {
|
||||||
+ if (CraftEventFactory.callEntityChangeBlockEvent(this, blockposition.getX(), blockposition.getY(), blockposition.getZ(), this.block.getBlock(), this.block.getBlock().toLegacyData(this.block)).isCancelled()) {
|
+ if (CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, this.block.getBlock(), this.block.getBlock().toLegacyData(this.block)).isCancelled()) {
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+ this.world.setTypeAndData(blockposition, this.block, 3);
|
+ this.world.setTypeAndData(blockposition, this.block, 3);
|
||||||
|
@ -128,7 +128,7 @@
|
|||||||
|
|
||||||
private void a(BlockPosition blockposition) {
|
private void a(BlockPosition blockposition) {
|
||||||
if (this.world.getType(blockposition).getBlock() == Blocks.FIRE) {
|
if (this.world.getType(blockposition).getBlock() == Blocks.FIRE) {
|
||||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this, blockposition.getX(), blockposition.getY(), blockposition.getZ(), Blocks.AIR, 0).isCancelled()) return; // CraftBukkit
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR, 0).isCancelled()) return; // CraftBukkit
|
||||||
this.world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 2);
|
this.world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
if (integer.intValue() == 0) {
|
if (integer.intValue() == 0) {
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.c, blockposition.getX(), blockposition.getY(), blockposition.getZ(), Blocks.AIR, 0).isCancelled()) {
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.c, blockposition, Blocks.AIR, 0).isCancelled()) {
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
@ -30,7 +30,7 @@
|
|||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(
|
||||||
+ this.c,
|
+ this.c,
|
||||||
+ blockposition.getX(), blockposition.getY(), blockposition.getZ(),
|
+ blockposition,
|
||||||
+ block, block.toLegacyData(iblockdata.set(BlockCarrots.AGE, Integer.valueOf(integer.intValue() - 1)))
|
+ block, block.toLegacyData(iblockdata.set(BlockCarrots.AGE, Integer.valueOf(integer.intValue() - 1)))
|
||||||
+ ).isCancelled()) {
|
+ ).isCancelled()) {
|
||||||
+ return;
|
+ return;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
if (BlockMonsterEggs.i(iblockdata)) {
|
if (BlockMonsterEggs.i(iblockdata)) {
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.silverfish, blockposition.getX(), blockposition.getY(), blockposition.getZ(), Blocks.MONSTER_EGG, Block.getId(BlockMonsterEggs.getById(iblockdata.getBlock().toLegacyData(iblockdata)))).isCancelled()) {
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.silverfish, blockposition, Blocks.MONSTER_EGG, Block.getId(BlockMonsterEggs.getById(iblockdata.getBlock().toLegacyData(iblockdata)))).isCancelled()) {
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
if (iblockdata.getBlock() == Blocks.MONSTER_EGG) {
|
if (iblockdata.getBlock() == Blocks.MONSTER_EGG) {
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.silverfish, blockposition1.getX(), blockposition1.getY(), blockposition1.getZ(), Blocks.AIR, 0).isCancelled()) {
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.silverfish, blockposition1, Blocks.AIR, 0).isCancelled()) {
|
||||||
+ continue;
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
|
|
||||||
if (iblockdata.getMaterial() != Material.AIR && a(block)) {
|
if (iblockdata.getMaterial() != Material.AIR && a(block)) {
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (CraftEventFactory.callEntityChangeBlockEvent(this, j2, k2, l2, Blocks.AIR, 0).isCancelled()) {
|
+ if (CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR, 0).isCancelled()) {
|
||||||
+ continue;
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
49
paper-server/nms-patches/PathfinderGoalVillagerFarm.patch
Normal file
49
paper-server/nms-patches/PathfinderGoalVillagerFarm.patch
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
--- a/net/minecraft/server/PathfinderGoalVillagerFarm.java
|
||||||
|
+++ b/net/minecraft/server/PathfinderGoalVillagerFarm.java
|
||||||
|
@@ -48,7 +48,11 @@
|
||||||
|
Block block = iblockdata.getBlock();
|
||||||
|
|
||||||
|
if (this.f == 0 && block instanceof BlockCrops && ((BlockCrops) block).y(iblockdata)) {
|
||||||
|
- world.setAir(blockposition, true);
|
||||||
|
+ // CraftBukkit start
|
||||||
|
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.c, blockposition, Blocks.AIR, 0).isCancelled()) {
|
||||||
|
+ world.setAir(blockposition, true);
|
||||||
|
+ }
|
||||||
|
+ // CraftBukkit end
|
||||||
|
} else if (this.f == 1 && iblockdata.getMaterial() == Material.AIR) {
|
||||||
|
InventorySubcontainer inventorysubcontainer = this.c.dj();
|
||||||
|
|
||||||
|
@@ -57,19 +61,29 @@
|
||||||
|
boolean flag = false;
|
||||||
|
|
||||||
|
if (itemstack != null) {
|
||||||
|
+ // CraftBukkit start
|
||||||
|
+ Block planted = null;
|
||||||
|
+
|
||||||
|
if (itemstack.getItem() == Items.WHEAT_SEEDS) {
|
||||||
|
- world.setTypeAndData(blockposition, Blocks.WHEAT.getBlockData(), 3);
|
||||||
|
+ planted = Blocks.WHEAT;
|
||||||
|
flag = true;
|
||||||
|
} else if (itemstack.getItem() == Items.POTATO) {
|
||||||
|
- world.setTypeAndData(blockposition, Blocks.POTATOES.getBlockData(), 3);
|
||||||
|
+ planted = Blocks.POTATOES;
|
||||||
|
flag = true;
|
||||||
|
} else if (itemstack.getItem() == Items.CARROT) {
|
||||||
|
- world.setTypeAndData(blockposition, Blocks.CARROTS.getBlockData(), 3);
|
||||||
|
+ planted = Blocks.CARROTS;
|
||||||
|
flag = true;
|
||||||
|
} else if (itemstack.getItem() == Items.BEETROOT_SEEDS) {
|
||||||
|
- world.setTypeAndData(blockposition, Blocks.BEETROOT.getBlockData(), 3);
|
||||||
|
+ planted = Blocks.BEETROOT;
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ if (planted != null && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.c, blockposition, planted, 0).isCancelled()) {
|
||||||
|
+ world.setTypeAndData(blockposition, planted.getBlockData(), 3);
|
||||||
|
+ } else {
|
||||||
|
+ flag = false;
|
||||||
|
+ }
|
||||||
|
+ // CraftBukkit end
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag) {
|
@ -686,8 +686,8 @@ public class CraftEventFactory {
|
|||||||
return callEntityChangeBlockEvent(entity.getBukkitEntity(), block, material, 0, cancelled);
|
return callEntityChangeBlockEvent(entity.getBukkitEntity(), block, material, 0, cancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EntityChangeBlockEvent callEntityChangeBlockEvent(Entity entity, int x, int y, int z, net.minecraft.server.Block type, int data) {
|
public static EntityChangeBlockEvent callEntityChangeBlockEvent(Entity entity, BlockPosition position, net.minecraft.server.Block type, int data) {
|
||||||
Block block = entity.world.getWorld().getBlockAt(x, y, z);
|
Block block = entity.world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
|
||||||
Material material = CraftMagicNumbers.getMaterial(type);
|
Material material = CraftMagicNumbers.getMaterial(type);
|
||||||
|
|
||||||
return callEntityChangeBlockEvent(entity.getBukkitEntity(), block, material, data);
|
return callEntityChangeBlockEvent(entity.getBukkitEntity(), block, material, data);
|
||||||
|
Loading…
Reference in New Issue
Block a user