Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-20 21:40:06 +01:00
Added dispenser event.
Dieser Commit ist enthalten in:
Ursprung
6cbd4cdf9e
Commit
98633a9f16
@ -1,6 +1,15 @@
|
|||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Dispenser;
|
||||||
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.event.block.BlockDamageEvent;
|
||||||
|
import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class BlockDispenser extends BlockContainer {
|
public class BlockDispenser extends BlockContainer {
|
||||||
|
|
||||||
@ -82,7 +91,16 @@ public class BlockDispenser extends BlockContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k);
|
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) world.getTileEntity(i, j, k);
|
||||||
ItemStack itemstack = tileentitydispenser.b();
|
// CraftBukkit start
|
||||||
|
int dispenseSlot = tileentitydispenser.findDispenseSlot();
|
||||||
|
ItemStack itemstack = null;
|
||||||
|
if (dispenseSlot > -1) {
|
||||||
|
itemstack = tileentitydispenser.getContents()[dispenseSlot];
|
||||||
|
|
||||||
|
// Copy item stack, because we want it to have 1 item
|
||||||
|
itemstack = new ItemStack(itemstack.id, 1, itemstack.damage);
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
double d0 = (double) i + (double) f * 0.5D + 0.5D;
|
double d0 = (double) i + (double) f * 0.5D + 0.5D;
|
||||||
double d1 = (double) j + 0.5D;
|
double d1 = (double) j + 0.5D;
|
||||||
double d2 = (double) k + (double) f1 * 0.5D + 0.5D;
|
double d2 = (double) k + (double) f1 * 0.5D + 0.5D;
|
||||||
@ -91,6 +109,37 @@ public class BlockDispenser extends BlockContainer {
|
|||||||
world.makeSound((double) i, (double) j, (double) k, "random.click", 1.0F, 1.2F);
|
world.makeSound((double) i, (double) j, (double) k, "random.click", 1.0F, 1.2F);
|
||||||
} else {
|
} else {
|
||||||
double d3;
|
double d3;
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
d3 = random.nextDouble() * 0.1D + 0.2D;
|
||||||
|
double motX = (double) f * d3;
|
||||||
|
double motY = 0.20000000298023224D;
|
||||||
|
double motZ = (double) f1 * d3;
|
||||||
|
motX += random.nextGaussian() * 0.007499999832361937D * 6.0D;
|
||||||
|
motY += random.nextGaussian() * 0.007499999832361937D * 6.0D;
|
||||||
|
motZ += random.nextGaussian() * 0.007499999832361937D * 6.0D;
|
||||||
|
|
||||||
|
CraftWorld craftWorld = ((WorldServer) world).getWorld();
|
||||||
|
CraftServer server = ((WorldServer) world).getServer();
|
||||||
|
CraftBlock block = (CraftBlock) craftWorld.getBlockAt(i, j, k);
|
||||||
|
org.bukkit.inventory.ItemStack bukkitItem = (new CraftItemStack(itemstack)).clone();
|
||||||
|
BlockDispenseEvent event = new BlockDispenseEvent(block, bukkitItem, new Vector(motX, motY, motZ));
|
||||||
|
server.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actually remove the item
|
||||||
|
tileentitydispenser.a(dispenseSlot, 1);
|
||||||
|
|
||||||
|
motX = event.getVelocity().getX();
|
||||||
|
motY = event.getVelocity().getY();
|
||||||
|
motZ = event.getVelocity().getZ();
|
||||||
|
|
||||||
|
itemstack = new ItemStack(event.getItem().getTypeId(),
|
||||||
|
event.getItem().getAmount(), event.getItem().getDurability());
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
if (itemstack.id == Item.ARROW.id) {
|
if (itemstack.id == Item.ARROW.id) {
|
||||||
EntityArrow entityarrow = new EntityArrow(world, d0, d1, d2);
|
EntityArrow entityarrow = new EntityArrow(world, d0, d1, d2);
|
||||||
@ -114,12 +163,11 @@ public class BlockDispenser extends BlockContainer {
|
|||||||
EntityItem entityitem = new EntityItem(world, d0, d1 - 0.3D, d2, itemstack);
|
EntityItem entityitem = new EntityItem(world, d0, d1 - 0.3D, d2, itemstack);
|
||||||
|
|
||||||
d3 = random.nextDouble() * 0.1D + 0.2D;
|
d3 = random.nextDouble() * 0.1D + 0.2D;
|
||||||
entityitem.motX = (double) f * d3;
|
// CraftBukkit start
|
||||||
entityitem.motY = 0.20000000298023224D;
|
entityitem.motX = motX;
|
||||||
entityitem.motZ = (double) f1 * d3;
|
entityitem.motY = motY;
|
||||||
entityitem.motX += random.nextGaussian() * 0.007499999832361937D * 6.0D;
|
entityitem.motZ = motZ;
|
||||||
entityitem.motY += random.nextGaussian() * 0.007499999832361937D * 6.0D;
|
// CraftBukkit end
|
||||||
entityitem.motZ += random.nextGaussian() * 0.007499999832361937D * 6.0D;
|
|
||||||
world.addEntity(entityitem);
|
world.addEntity(entityitem);
|
||||||
world.makeSound((double) i, (double) j, (double) k, "random.click", 1.0F, 1.0F);
|
world.makeSound((double) i, (double) j, (double) k, "random.click", 1.0F, 1.0F);
|
||||||
}
|
}
|
||||||
|
@ -46,16 +46,24 @@ public class TileEntityDispenser extends TileEntity implements IInventory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack b() {
|
// CraftBukkit start
|
||||||
|
public int findDispenseSlot() {
|
||||||
int i = -1;
|
int i = -1;
|
||||||
int j = 1;
|
int j = 1;
|
||||||
|
|
||||||
for (int k = 0; k < this.items.length; ++k) {
|
for (int k = 0; k < this.items.length; ++k) {
|
||||||
if (this.items[k] != null && this.b.nextInt(j) == 0) {
|
if (this.items[k] != null && this.items[k].count != 0 && this.b.nextInt(j) == 0) {
|
||||||
i = k;
|
i = k;
|
||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack b() {
|
||||||
|
int i = findDispenseSlot();
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
return this.a(i, 1);
|
return this.a(i, 1);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren