mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 12:11:47 +01:00
Fire BlockDispenseEvent for new dispenser behaviors. Fixes BUKKIT-3774
This commit is contained in:
parent
fbe609bdbe
commit
0e60f1f7b8
4 changed files with 131 additions and 5 deletions
|
@ -2,6 +2,11 @@ package net.minecraft.server;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
final class DispenseBehaviorArmor extends DispenseBehaviorItem {
|
final class DispenseBehaviorArmor extends DispenseBehaviorItem {
|
||||||
|
|
||||||
DispenseBehaviorArmor() {}
|
DispenseBehaviorArmor() {}
|
||||||
|
@ -18,12 +23,39 @@ final class DispenseBehaviorArmor extends DispenseBehaviorItem {
|
||||||
EntityLiving entityliving = (EntityLiving) list.get(0);
|
EntityLiving entityliving = (EntityLiving) list.get(0);
|
||||||
int l = entityliving instanceof EntityHuman ? 1 : 0;
|
int l = entityliving instanceof EntityHuman ? 1 : 0;
|
||||||
int i1 = EntityLiving.b(itemstack);
|
int i1 = EntityLiving.b(itemstack);
|
||||||
ItemStack itemstack1 = itemstack.cloneItemStack();
|
|
||||||
|
// CraftBukkit start
|
||||||
|
ItemStack itemstack1 = itemstack.a(1);
|
||||||
|
World world = isourceblock.k();
|
||||||
|
org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ());
|
||||||
|
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
|
||||||
|
|
||||||
|
BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
|
||||||
|
if (!BlockDispenser.eventFired) {
|
||||||
|
world.getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
itemstack.count++;
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event.getItem().equals(craftItem)) {
|
||||||
|
itemstack.count++;
|
||||||
|
// Chain to handler for new item
|
||||||
|
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
|
||||||
|
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
|
||||||
|
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
|
||||||
|
idispensebehavior.a(isourceblock, eventStack);
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
itemstack1.count = 1;
|
itemstack1.count = 1;
|
||||||
entityliving.setEquipment(i1 - l, itemstack1);
|
entityliving.setEquipment(i1 - l, itemstack1);
|
||||||
entityliving.a(i1, 2.0F);
|
entityliving.a(i1, 2.0F);
|
||||||
--itemstack.count;
|
// --itemstack.count; // CraftBukkit - handled above
|
||||||
return itemstack;
|
return itemstack;
|
||||||
} else {
|
} else {
|
||||||
return super.b(isourceblock, itemstack);
|
return super.b(isourceblock, itemstack);
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
final class DispenseBehaviorBonemeal extends DispenseBehaviorItem {
|
final class DispenseBehaviorBonemeal extends DispenseBehaviorItem {
|
||||||
|
|
||||||
private boolean b = true;
|
private boolean b = true;
|
||||||
|
@ -14,7 +19,34 @@ final class DispenseBehaviorBonemeal extends DispenseBehaviorItem {
|
||||||
int j = isourceblock.getBlockY() + enumfacing.d();
|
int j = isourceblock.getBlockY() + enumfacing.d();
|
||||||
int k = isourceblock.getBlockZ() + enumfacing.e();
|
int k = isourceblock.getBlockZ() + enumfacing.e();
|
||||||
|
|
||||||
if (ItemDye.a(itemstack, world, i, j, k)) {
|
// CraftBukkit start
|
||||||
|
ItemStack itemstack1 = itemstack.a(1);
|
||||||
|
org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ());
|
||||||
|
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
|
||||||
|
|
||||||
|
BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
|
||||||
|
if (!BlockDispenser.eventFired) {
|
||||||
|
world.getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
itemstack.count++;
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event.getItem().equals(craftItem)) {
|
||||||
|
itemstack.count++;
|
||||||
|
// Chain to handler for new item
|
||||||
|
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
|
||||||
|
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
|
||||||
|
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
|
||||||
|
idispensebehavior.a(isourceblock, eventStack);
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
|
if (ItemDye.a(itemstack1, world, i, j, k)) { // CraftBukkit - itemstack -> itemstack1
|
||||||
if (!world.isStatic) {
|
if (!world.isStatic) {
|
||||||
world.triggerEffect(2005, i, j, k, 0);
|
world.triggerEffect(2005, i, j, k, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
final class DispenseBehaviorFlintAndSteel extends DispenseBehaviorItem {
|
final class DispenseBehaviorFlintAndSteel extends DispenseBehaviorItem {
|
||||||
|
|
||||||
private boolean b = true;
|
private boolean b = true;
|
||||||
|
@ -13,6 +18,30 @@ final class DispenseBehaviorFlintAndSteel extends DispenseBehaviorItem {
|
||||||
int j = isourceblock.getBlockY() + enumfacing.d();
|
int j = isourceblock.getBlockY() + enumfacing.d();
|
||||||
int k = isourceblock.getBlockZ() + enumfacing.e();
|
int k = isourceblock.getBlockZ() + enumfacing.e();
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ());
|
||||||
|
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
|
||||||
|
|
||||||
|
BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(0, 0, 0));
|
||||||
|
if (!BlockDispenser.eventFired) {
|
||||||
|
world.getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event.getItem().equals(craftItem)) {
|
||||||
|
// Chain to handler for new item
|
||||||
|
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
|
||||||
|
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
|
||||||
|
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
|
||||||
|
idispensebehavior.a(isourceblock, eventStack);
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
if (world.isEmpty(i, j, k)) {
|
if (world.isEmpty(i, j, k)) {
|
||||||
world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||||
if (itemstack.isDamaged(1, world.random)) {
|
if (itemstack.isDamaged(1, world.random)) {
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.event.block.BlockDispenseEvent;
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
final class DispenseBehaviorTNT extends DispenseBehaviorItem {
|
final class DispenseBehaviorTNT extends DispenseBehaviorItem {
|
||||||
|
|
||||||
DispenseBehaviorTNT() {}
|
DispenseBehaviorTNT() {}
|
||||||
|
@ -10,10 +15,38 @@ final class DispenseBehaviorTNT extends DispenseBehaviorItem {
|
||||||
int i = isourceblock.getBlockX() + enumfacing.c();
|
int i = isourceblock.getBlockX() + enumfacing.c();
|
||||||
int j = isourceblock.getBlockY() + enumfacing.d();
|
int j = isourceblock.getBlockY() + enumfacing.d();
|
||||||
int k = isourceblock.getBlockZ() + enumfacing.e();
|
int k = isourceblock.getBlockZ() + enumfacing.e();
|
||||||
EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), (EntityLiving) null);
|
|
||||||
|
|
||||||
world.addEntity(entitytntprimed);
|
// CraftBukkit start
|
||||||
--itemstack.count;
|
ItemStack itemstack1 = itemstack.a(1);
|
||||||
|
org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ());
|
||||||
|
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
|
||||||
|
|
||||||
|
BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(i + 0.5, j + 0.5, k + 0.5));
|
||||||
|
if (!BlockDispenser.eventFired) {
|
||||||
|
world.getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
itemstack.count++;
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event.getItem().equals(craftItem)) {
|
||||||
|
itemstack.count++;
|
||||||
|
// Chain to handler for new item
|
||||||
|
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
|
||||||
|
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
|
||||||
|
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
|
||||||
|
idispensebehavior.a(isourceblock, eventStack);
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), (EntityLiving) null);
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
|
world.addEntity(entitytntprimed);
|
||||||
|
// --itemstack.count; // CraftBukkit - handled above
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue