mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
SPIGOT-3149: StructureGrowEvent for dispenser triggered growth
This commit is contained in:
parent
f4822eb93d
commit
186c351a3a
@ -1,18 +1,22 @@
|
||||
--- a/net/minecraft/server/DispenserRegistry.java
|
||||
+++ b/net/minecraft/server/DispenserRegistry.java
|
||||
@@ -7,6 +7,11 @@
|
||||
@@ -7,6 +7,15 @@
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import java.util.List;
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.TreeType;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.event.block.BlockDispenseEvent;
|
||||
+import org.bukkit.event.world.StructureGrowEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class DispenserRegistry {
|
||||
|
||||
public static final PrintStream a = System.out;
|
||||
@@ -69,7 +74,7 @@
|
||||
@@ -69,7 +78,7 @@
|
||||
BlockDispenser.REGISTRY.a(Items.SPLASH_POTION, new IDispenseBehavior() {
|
||||
public ItemStack a(ISourceBlock isourceblock, final ItemStack itemstack) {
|
||||
return (new DispenseBehaviorProjectile() {
|
||||
@ -21,7 +25,7 @@
|
||||
return new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), itemstack1.cloneItemStack());
|
||||
}
|
||||
|
||||
@@ -86,7 +91,7 @@
|
||||
@@ -86,7 +95,7 @@
|
||||
BlockDispenser.REGISTRY.a(Items.LINGERING_POTION, new IDispenseBehavior() {
|
||||
public ItemStack a(ISourceBlock isourceblock, final ItemStack itemstack) {
|
||||
return (new DispenseBehaviorProjectile() {
|
||||
@ -30,7 +34,7 @@
|
||||
return new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), itemstack1.cloneItemStack());
|
||||
}
|
||||
|
||||
@@ -106,14 +111,46 @@
|
||||
@@ -106,14 +115,46 @@
|
||||
double d0 = isourceblock.getX() + (double) enumdirection.getAdjacentX();
|
||||
double d1 = (double) ((float) (isourceblock.getBlockPosition().getY() + enumdirection.getAdjacentY()) + 0.2F);
|
||||
double d2 = isourceblock.getZ() + (double) enumdirection.getAdjacentZ();
|
||||
@ -79,7 +83,7 @@
|
||||
return itemstack;
|
||||
}
|
||||
});
|
||||
@@ -123,10 +160,39 @@
|
||||
@@ -123,10 +164,39 @@
|
||||
double d0 = isourceblock.getX() + (double) enumdirection.getAdjacentX();
|
||||
double d1 = (double) ((float) isourceblock.getBlockPosition().getY() + 0.2F);
|
||||
double d2 = isourceblock.getZ() + (double) enumdirection.getAdjacentZ();
|
||||
@ -121,7 +125,7 @@
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@@ -147,8 +213,38 @@
|
||||
@@ -147,8 +217,38 @@
|
||||
double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentY();
|
||||
double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentZ();
|
||||
|
||||
@ -162,7 +166,7 @@
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@@ -169,7 +265,53 @@
|
||||
@@ -169,7 +269,53 @@
|
||||
ItemBucket itembucket = (ItemBucket) itemstack.getItem();
|
||||
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
|
||||
|
||||
@ -217,7 +221,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
@@ -196,6 +338,30 @@
|
||||
@@ -196,6 +342,30 @@
|
||||
item = Items.LAVA_BUCKET;
|
||||
}
|
||||
|
||||
@ -248,7 +252,7 @@
|
||||
world.setAir(blockposition);
|
||||
itemstack.subtract(1);
|
||||
if (itemstack.isEmpty()) {
|
||||
@@ -213,14 +379,42 @@
|
||||
@@ -213,14 +383,42 @@
|
||||
protected ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
|
||||
World world = isourceblock.getWorld();
|
||||
|
||||
@ -294,7 +298,7 @@
|
||||
} else if (world.getType(blockposition).getBlock() == Blocks.TNT) {
|
||||
Blocks.TNT.postBreak(world, blockposition, Blocks.TNT.getBlockData().set(BlockTNT.EXPLODE, Boolean.valueOf(true)));
|
||||
world.setAir(blockposition);
|
||||
@@ -238,6 +432,30 @@
|
||||
@@ -238,6 +436,32 @@
|
||||
World world = isourceblock.getWorld();
|
||||
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
|
||||
|
||||
@ -320,12 +324,41 @@
|
||||
+ return itemstack;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ world.captureTreeGeneration = true;
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
if (ItemDye.a(itemstack, world, blockposition)) {
|
||||
if (!world.isClientSide) {
|
||||
world.triggerEffect(2005, blockposition, 0);
|
||||
@@ -256,11 +474,40 @@
|
||||
@@ -245,6 +469,26 @@
|
||||
} else {
|
||||
this.b = false;
|
||||
}
|
||||
+ // CraftBukkit start
|
||||
+ world.captureTreeGeneration = false;
|
||||
+ if (world.capturedBlockStates.size() > 0) {
|
||||
+ TreeType treeType = BlockSapling.treeType;
|
||||
+ BlockSapling.treeType = null;
|
||||
+ Location location = new Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
|
||||
+ List<org.bukkit.block.BlockState> blocks = (List<org.bukkit.block.BlockState>) world.capturedBlockStates.clone();
|
||||
+ world.capturedBlockStates.clear();
|
||||
+ StructureGrowEvent structureEvent = null;
|
||||
+ if (treeType != null) {
|
||||
+ structureEvent = new StructureGrowEvent(location, treeType, false, null, blocks);
|
||||
+ org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent);
|
||||
+ }
|
||||
+ if (structureEvent == null || !structureEvent.isCancelled()) {
|
||||
+ for (org.bukkit.block.BlockState blockstate : blocks) {
|
||||
+ blockstate.update(true);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
return itemstack;
|
||||
} else {
|
||||
@@ -256,11 +500,40 @@
|
||||
protected ItemStack b(ISourceBlock isourceblock, ItemStack itemstack) {
|
||||
World world = isourceblock.getWorld();
|
||||
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
|
||||
@ -368,7 +401,7 @@
|
||||
return itemstack;
|
||||
}
|
||||
});
|
||||
@@ -271,6 +518,30 @@
|
||||
@@ -271,6 +544,30 @@
|
||||
BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
|
||||
BlockSkull blockskull = Blocks.SKULL;
|
||||
|
||||
@ -399,7 +432,7 @@
|
||||
this.b = true;
|
||||
if (world.isEmpty(blockposition) && blockskull.b(world, blockposition, itemstack)) {
|
||||
if (!world.isClientSide) {
|
||||
@@ -319,6 +590,30 @@
|
||||
@@ -319,6 +616,30 @@
|
||||
BlockPosition blockposition = isourceblock.getBlockPosition().shift((EnumDirection) isourceblock.e().get(BlockDispenser.FACING));
|
||||
BlockPumpkin blockpumpkin = (BlockPumpkin) Blocks.PUMPKIN;
|
||||
|
||||
@ -430,7 +463,7 @@
|
||||
this.b = true;
|
||||
if (world.isEmpty(blockposition) && blockpumpkin.b(world, blockposition)) {
|
||||
if (!world.isClientSide) {
|
||||
@@ -388,6 +683,30 @@
|
||||
@@ -388,6 +709,30 @@
|
||||
EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING);
|
||||
BlockPosition blockposition = isourceblock.getBlockPosition().shift(enumdirection);
|
||||
|
||||
@ -461,7 +494,7 @@
|
||||
this.b = world.a(block, blockposition, false, EnumDirection.DOWN, (Entity) null);
|
||||
if (this.b) {
|
||||
EnumDirection enumdirection1 = world.isEmpty(blockposition.down()) ? enumdirection : EnumDirection.UP;
|
||||
@@ -456,12 +775,40 @@
|
||||
@@ -456,12 +801,40 @@
|
||||
d3 = 0.0D;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user