#1209: Clean up various patches

By: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
This commit is contained in:
CraftBukkit/Spigot
2023-06-24 17:15:05 +10:00
parent 0f9e7a497e
commit b97cc9b99f
71 changed files with 662 additions and 719 deletions

View File

@@ -84,7 +84,7 @@
+ // CraftBukkit start
+ private static boolean setTilt(IBlockData iblockdata, World world, BlockPosition blockposition, Tilt tilt, @Nullable Entity entity) {
+ if (entity != null) {
+ if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata.setValue(BigDripleafBlock.TILT, tilt)).isCancelled()) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata.setValue(BigDripleafBlock.TILT, tilt))) {
+ return false;
+ }
+ }

View File

@@ -43,7 +43,7 @@
worldserver.setBlock(blockposition, this.plant.getStateForPlacement(worldserver, blockposition), 2);
} else {
- this.placeDeadFlower(worldserver, blockposition);
+ // CraftBukkit - add event
+ // CraftBukkit start - add event
+ if (CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, this.defaultBlockState().setValue(BlockChorusFlower.AGE, Integer.valueOf(5)), 2)) {
+ this.placeDeadFlower(worldserver, blockposition);
+ }
@@ -51,7 +51,7 @@
}
} else {
- this.placeDeadFlower(worldserver, blockposition);
+ // CraftBukkit - add event
+ // CraftBukkit start - add event
+ if (CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, this.defaultBlockState().setValue(BlockChorusFlower.AGE, Integer.valueOf(5)), 2)) {
+ this.placeDeadFlower(worldserver, blockposition);
+ }
@@ -63,8 +63,8 @@
BlockPosition blockposition = movingobjectpositionblock.getBlockPos();
if (!world.isClientSide && iprojectile.mayInteract(world, blockposition) && iprojectile.getType().is(TagsEntity.IMPACT_PROJECTILES)) {
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState()).isCancelled()) {
+ // CraftBukkit
+ if (!CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end

View File

@@ -1,11 +1,10 @@
--- a/net/minecraft/world/level/block/BlockComposter.java
+++ b/net/minecraft/world/level/block/BlockComposter.java
@@ -40,6 +40,12 @@
@@ -40,6 +40,11 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// CraftBukkit start
+import net.minecraft.world.entity.Entity;
+import org.bukkit.craftbukkit.inventory.CraftBlockInventoryHolder;
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
+// CraftBukkit end
@@ -13,7 +12,7 @@
public class BlockComposter extends Block implements IInventoryHolder {
public static final int READY = 8;
@@ -248,7 +254,14 @@
@@ -248,7 +253,14 @@
int i = (Integer) iblockdata.getValue(BlockComposter.LEVEL);
if (i < 7 && BlockComposter.COMPOSTABLES.containsKey(itemstack.getItem())) {
@@ -21,7 +20,7 @@
+ // CraftBukkit start
+ double rand = worldserver.getRandom().nextDouble();
+ IBlockData iblockdata1 = addItem(entity, iblockdata, DummyGeneratorAccess.INSTANCE, blockposition, itemstack, rand);
+ if (iblockdata == iblockdata1 || org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1).isCancelled()) {
+ if (iblockdata == iblockdata1 || !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1)) {
+ return iblockdata;
+ }
+ iblockdata1 = addItem(entity, iblockdata, worldserver, blockposition, itemstack, rand);
@@ -29,14 +28,14 @@
itemstack.shrink(1);
return iblockdata1;
@@ -258,6 +271,14 @@
@@ -258,6 +270,14 @@
}
public static IBlockData extractProduce(Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) {
+ // CraftBukkit start
+ if (entity != null && !(entity instanceof EntityHuman)) {
+ IBlockData iblockdata1 = empty(entity, iblockdata, DummyGeneratorAccess.INSTANCE, blockposition);
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1).isCancelled()) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1)) {
+ return iblockdata;
+ }
+ }
@@ -44,7 +43,7 @@
if (!world.isClientSide) {
Vec3D vec3d = Vec3D.atLowerCornerWithOffset(blockposition, 0.5D, 1.01D, 0.5D).offsetRandom(world.random, 0.7F);
EntityItem entityitem = new EntityItem(world, vec3d.x(), vec3d.y(), vec3d.z(), new ItemStack(Items.BONE_MEAL));
@@ -281,10 +302,16 @@
@@ -281,10 +301,16 @@
}
static IBlockData addItem(@Nullable Entity entity, IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack) {
@@ -62,7 +61,7 @@
return iblockdata;
} else {
int j = i + 1;
@@ -333,7 +360,8 @@
@@ -333,7 +359,8 @@
public IWorldInventory getContainer(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
int i = (Integer) iblockdata.getValue(BlockComposter.LEVEL);
@@ -72,7 +71,7 @@
}
public static class ContainerOutput extends InventorySubcontainer implements IWorldInventory {
@@ -348,6 +376,7 @@
@@ -348,6 +375,7 @@
this.state = iblockdata;
this.level = generatoraccess;
this.pos = blockposition;
@@ -80,16 +79,14 @@
}
@Override
@@ -372,8 +401,15 @@
@@ -372,8 +400,15 @@
@Override
public void setChanged() {
- BlockComposter.empty((Entity) null, this.state, this.level, this.pos);
- this.changed = true;
+ // CraftBukkit start - allow putting items back (eg cancelled InventoryMoveItemEvent)
+ if (this.isEmpty()) {
+ BlockComposter.empty((Entity) null, this.state, this.level, this.pos);
+ this.changed = true;
BlockComposter.empty((Entity) null, this.state, this.level, this.pos);
this.changed = true;
+ } else {
+ this.level.setBlock(this.pos, this.state, 3);
+ this.changed = false;
@@ -98,7 +95,7 @@
}
}
@@ -386,6 +422,7 @@
@@ -386,6 +421,7 @@
public ContainerInput(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
super(1);
@@ -106,7 +103,7 @@
this.state = iblockdata;
this.level = generatoraccess;
this.pos = blockposition;
@@ -428,8 +465,9 @@
@@ -428,8 +464,9 @@
public static class ContainerEmpty extends InventorySubcontainer implements IWorldInventory {

View File

@@ -32,7 +32,7 @@
@Override
public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
- if (entity instanceof EntityRavager && world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
+ if (entity instanceof EntityRavager && !CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState(), !world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)).isCancelled()) { // CraftBukkit
+ if (entity instanceof EntityRavager && CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState(), !world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit
world.destroyBlock(blockposition, true, entity);
}

View File

@@ -60,7 +60,7 @@
spawnParticles(world, blockposition);
if (!(Boolean) iblockdata.getValue(BlockRedstoneOre.LIT)) {
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata.setValue(BlockRedstoneOre.LIT, true)).isCancelled()) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata.setValue(BlockRedstoneOre.LIT, true))) {
+ return;
+ }
+ // CraftBukkit end

View File

@@ -45,7 +45,7 @@
+ return;
+ }
+
+ if (CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.DIRT.defaultBlockState()).isCancelled()) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.DIRT.defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end

View File

@@ -56,7 +56,7 @@
if (iprojectile.isOnFire() && iprojectile.mayInteract(world, blockposition)) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState()).isCancelled() || !CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.PROJECTILE, iprojectile, null)) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState()) || !CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.PROJECTILE, iprojectile, null)) {
+ return;
+ }
+ // CraftBukkit end

View File

@@ -1,11 +1,25 @@
--- a/net/minecraft/world/level/block/BlockWaterLily.java
+++ b/net/minecraft/world/level/block/BlockWaterLily.java
@@ -24,7 +24,7 @@
@Override
@@ -13,6 +13,10 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class BlockWaterLily extends BlockPlant {
protected static final VoxelShape AABB = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 1.5D, 15.0D);
@@ -25,6 +29,11 @@
public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
super.entityInside(iblockdata, world, blockposition, entity);
- if (world instanceof WorldServer && entity instanceof EntityBoat) {
+ if (world instanceof WorldServer && entity instanceof EntityBoat && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState()).isCancelled()) { // CraftBukkit
if (world instanceof WorldServer && entity instanceof EntityBoat) {
+ // CraftBukkit start
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end
world.destroyBlock(new BlockPosition(blockposition), true, entity);
}

View File

@@ -1,12 +1,11 @@
--- a/net/minecraft/world/level/block/CaveVines.java
+++ b/net/minecraft/world/level/block/CaveVines.java
@@ -18,6 +18,14 @@
@@ -18,6 +18,13 @@
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.shapes.VoxelShape;
+// CraftBukkit start
+import java.util.Collections;
+import net.minecraft.world.entity.Entity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerHarvestBlockEvent;
@@ -15,13 +14,13 @@
public interface CaveVines {
VoxelShape SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 16.0D, 15.0D);
@@ -25,7 +33,24 @@
@@ -25,7 +32,24 @@
static EnumInteractionResult use(@Nullable Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) {
if ((Boolean) iblockdata.getValue(CaveVines.BERRIES)) {
- Block.popResource(world, blockposition, new ItemStack(Items.GLOW_BERRIES, 1));
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, (IBlockData) iblockdata.setValue(CaveVines.BERRIES, false)).isCancelled()) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, (IBlockData) iblockdata.setValue(CaveVines.BERRIES, false))) {
+ return EnumInteractionResult.SUCCESS;
+ }
+

View File

@@ -17,7 +17,7 @@
if (!world.isClientSide && iprojectile.mayInteract(world, blockposition) && iprojectile instanceof EntityThrownTrident && iprojectile.getDeltaMovement().length() > 0.6D) {
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState()).isCancelled()) {
+ if (!CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end

View File

@@ -7,7 +7,7 @@
- if (entity.isOnFire() && (world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) || entity instanceof EntityHuman) && entity.mayInteract(world, blockposition)) {
+ // CraftBukkit start
+ if (entity.isOnFire() && entity.mayInteract(world, blockposition)) {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState(), !(world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) || entity instanceof EntityHuman)).isCancelled()) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState(), !(world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) || entity instanceof EntityHuman))) {
+ return;
+ }
+ // CraftBukkit end