Archiviert
13
0

SPIGOT-2490: Villager farming event

Dieser Commit ist enthalten in:
md_5 2016-07-08 11:12:40 +10:00
Ursprung a327d9f1da
Commit d7c257e120
11 geänderte Dateien mit 63 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -56,7 +56,7 @@
this.playEffect(world, blockposition);
if (this == Blocks.REDSTONE_ORE) {
+ // 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;
+ }
+ // CraftBukkit end

Datei anzeigen

@ -45,7 +45,7 @@
+ 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;
+ }
+ // CraftBukkit end

Datei anzeigen

@ -5,7 +5,7 @@
public void a(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) {
super.a(world, blockposition, iblockdata, entity);
- 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);
}

Datei anzeigen

@ -56,7 +56,7 @@
if (iblockdata2 != null && this.a(world, blockposition, iblockdata2.getBlock(), iblockdata, iblockdata1)) {
+ // 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);
this.a.setCarried((IBlockData) null);
+ }

Datei anzeigen

@ -14,7 +14,7 @@
if (this.ticksLived++ == 0) {
blockposition = new BlockPosition(this);
- 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);
} else if (!this.world.isClientSide) {
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)) {
+ // CraftBukkit start
+ 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;
+ }
+ this.world.setTypeAndData(blockposition, this.block, 3);

Datei anzeigen

@ -128,7 +128,7 @@
private void a(BlockPosition blockposition) {
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);
}

Datei anzeigen

@ -20,7 +20,7 @@
if (integer.intValue() == 0) {
+ // 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;
+ }
+ // CraftBukkit end
@ -30,7 +30,7 @@
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(
+ this.c,
+ blockposition.getX(), blockposition.getY(), blockposition.getZ(),
+ blockposition,
+ block, block.toLegacyData(iblockdata.set(BlockCarrots.AGE, Integer.valueOf(integer.intValue() - 1)))
+ ).isCancelled()) {
+ return;

Datei anzeigen

@ -5,7 +5,7 @@
if (BlockMonsterEggs.i(iblockdata)) {
+ // 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;
+ }
+ // CraftBukkit end
@ -17,7 +17,7 @@
if (iblockdata.getBlock() == Blocks.MONSTER_EGG) {
+ // 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;
+ }
+ // CraftBukkit end

Datei anzeigen

@ -60,7 +60,7 @@
if (iblockdata.getMaterial() != Material.AIR && a(block)) {
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityChangeBlockEvent(this, j2, k2, l2, Blocks.AIR, 0).isCancelled()) {
+ if (CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR, 0).isCancelled()) {
+ continue;
+ }
+ // CraftBukkit end

Datei anzeigen

@ -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) {

Datei anzeigen

@ -686,8 +686,8 @@ public class CraftEventFactory {
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) {
Block block = entity.world.getWorld().getBlockAt(x, y, z);
public static EntityChangeBlockEvent callEntityChangeBlockEvent(Entity entity, BlockPosition position, net.minecraft.server.Block type, int data) {
Block block = entity.world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
Material material = CraftMagicNumbers.getMaterial(type);
return callEntityChangeBlockEvent(entity.getBukkitEntity(), block, material, data);