mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-11 17:31:06 +01:00
Implement Bucket events
This commit is contained in:
parent
324efa8224
commit
bb9558adec
2 changed files with 124 additions and 30 deletions
72
src/main/java/net/minecraft/server/EntityCow.java
Normal file
72
src/main/java/net/minecraft/server/EntityCow.java
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
|
public class EntityCow extends EntityAnimal {
|
||||||
|
|
||||||
|
public EntityCow(World world) {
|
||||||
|
super(world);
|
||||||
|
this.texture = "/mob/cow.png";
|
||||||
|
this.a(0.9F, 1.3F);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(NBTTagCompound nbttagcompound) {
|
||||||
|
super.a(nbttagcompound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void b(NBTTagCompound nbttagcompound) {
|
||||||
|
super.b(nbttagcompound);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String e() {
|
||||||
|
return "mob.cow";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String f() {
|
||||||
|
return "mob.cowhurt";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String g() {
|
||||||
|
return "mob.cowhurt";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected float i() {
|
||||||
|
return 0.4F;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int h() {
|
||||||
|
return Item.LEATHER.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean a(EntityHuman entityhuman) {
|
||||||
|
ItemStack itemstack = entityhuman.inventory.b();
|
||||||
|
|
||||||
|
if (itemstack != null && itemstack.id == Item.BUCKET.id) {
|
||||||
|
// CraftBukkit start - got milk?
|
||||||
|
Location loc = this.getBukkitEntity().getLocation();
|
||||||
|
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), -1, itemstack, Item.MILK_BUCKET);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
||||||
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
||||||
|
itemstack = new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data );
|
||||||
|
|
||||||
|
entityhuman.inventory.a(entityhuman.inventory.c, itemstack);
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,17 @@
|
||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||||
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.craftbukkit.CraftWorld;
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event.Type;
|
import org.bukkit.event.Event.Type;
|
||||||
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
|
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||||
import org.bukkit.event.player.PlayerItemEvent;
|
import org.bukkit.event.player.PlayerItemEvent;
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
|
@ -52,49 +56,53 @@ public class ItemBucket extends Item {
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CraftBukkit start - Click == placed when handling an empty bucket!
|
|
||||||
CraftWorld craftWorld = ((WorldServer) world).getWorld();
|
|
||||||
CraftServer craftServer = ((WorldServer) world).getServer();
|
|
||||||
|
|
||||||
Type eventType = Type.PLAYER_ITEM;
|
|
||||||
Player who = (entityhuman == null) ? null : (Player) entityhuman.getBukkitEntity();
|
|
||||||
org.bukkit.inventory.ItemStack itemInHand = new CraftItemStack(itemstack);
|
|
||||||
org.bukkit.block.Block blockClicked = craftWorld.getBlockAt(i, j, k);
|
|
||||||
BlockFace blockFace = CraftBlock.notchToBlockFace(movingobjectposition.e);
|
|
||||||
// CraftBukkit end
|
|
||||||
|
|
||||||
if (this.a == 0) {
|
if (this.a == 0) {
|
||||||
if (world.getMaterial(i, j, k) == Material.WATER && world.getData(i, j, k) == 0) {
|
if (world.getMaterial(i, j, k) == Material.WATER && world.getData(i, j, k) == 0) {
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace);
|
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Item.WATER_BUCKET);
|
||||||
craftServer.getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
||||||
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
world.e(i, j, k, 0);
|
world.e(i, j, k, 0);
|
||||||
return new ItemStack(Item.WATER_BUCKET);
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world.getMaterial(i, j, k) == Material.LAVA && world.getData(i, j, k) == 0) {
|
if (world.getMaterial(i, j, k) == Material.LAVA && world.getData(i, j, k) == 0) {
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace);
|
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Item.LAVA_BUCKET);
|
||||||
craftServer.getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
||||||
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
world.e(i, j, k, 0);
|
world.e(i, j, k, 0);
|
||||||
return new ItemStack(Item.LAVA_BUCKET);
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data ); // CraftBukkit
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.a < 0) {
|
if (this.a < 0) {
|
||||||
return new ItemStack(Item.BUCKET);
|
// CraftBukkit start
|
||||||
|
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, i, j, k, movingobjectposition.e, itemstack);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
||||||
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
||||||
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data );
|
||||||
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
|
int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit
|
||||||
|
|
||||||
if (movingobjectposition.e == 0) {
|
if (movingobjectposition.e == 0) {
|
||||||
--j;
|
--j;
|
||||||
|
@ -121,6 +129,14 @@ public class ItemBucket extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world.isEmpty(i, j, k) || !world.getMaterial(i, j, k).isBuildable()) {
|
if (world.isEmpty(i, j, k) || !world.getMaterial(i, j, k).isBuildable()) {
|
||||||
|
// CraftBukkit start
|
||||||
|
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clickedX, clickedY, clickedZ, movingobjectposition.e, itemstack);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
if (world.m.d && this.a == Block.WATER.id) {
|
if (world.m.d && this.a == Block.WATER.id) {
|
||||||
world.a(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (world.k.nextFloat() - world.k.nextFloat()) * 0.8F);
|
world.a(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (world.k.nextFloat() - world.k.nextFloat()) * 0.8F);
|
||||||
|
|
||||||
|
@ -128,23 +144,29 @@ public class ItemBucket extends Item {
|
||||||
world.a("largesmoke", (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
|
world.a("largesmoke", (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// CraftBukkit start - bucket empty.
|
|
||||||
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace);
|
|
||||||
craftServer.getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return itemstack;
|
|
||||||
}
|
|
||||||
// CraftBukkit end
|
|
||||||
|
|
||||||
world.b(i, j, k, this.a, 0);
|
world.b(i, j, k, this.a, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ItemStack(Item.BUCKET);
|
// CraftBukkit start
|
||||||
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
||||||
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
||||||
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data );
|
||||||
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (this.a == 0 && movingobjectposition.g instanceof EntityCow) {
|
} else if (this.a == 0 && movingobjectposition.g instanceof EntityCow) {
|
||||||
return new ItemStack(Item.MILK_BUCKET);
|
// CraftBukkit start -- This codepath seems to be *NEVER* called
|
||||||
|
Location loc = movingobjectposition.g.getBukkitEntity().getLocation();
|
||||||
|
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), -1, itemstack, Item.MILK_BUCKET);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
||||||
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
||||||
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data );
|
||||||
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemstack;
|
return itemstack;
|
||||||
|
|
Loading…
Reference in a new issue