SPIGOT-5710: POI data mismatch when cancelling BlockPlaceEvent for villager workstations

This commit is contained in:
DerFrZocker 2021-07-03 15:39:52 +10:00 committed by md_5
parent 1e8368ea8d
commit bc00005d0e
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 27 additions and 20 deletions

View File

@ -103,7 +103,7 @@
EntityHuman entityhuman = itemactioncontext.getEntity(); EntityHuman entityhuman = itemactioncontext.getEntity();
BlockPosition blockposition = itemactioncontext.getClickPosition(); BlockPosition blockposition = itemactioncontext.getClickPosition();
ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false); ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false);
@@ -204,12 +256,153 @@ @@ -204,12 +256,155 @@
if (entityhuman != null && !entityhuman.getAbilities().mayBuild && !this.b(itemactioncontext.getWorld().r(), shapedetectorblock)) { if (entityhuman != null && !entityhuman.getAbilities().mayBuild && !this.b(itemactioncontext.getWorld().r(), shapedetectorblock)) {
return EnumInteractionResult.PASS; return EnumInteractionResult.PASS;
} else { } else {
@ -175,9 +175,11 @@
+ // PAIL: Remove this when MC-99075 fixed + // PAIL: Remove this when MC-99075 fixed
+ placeEvent.getPlayer().updateInventory(); + placeEvent.getPlayer().updateInventory();
+ // revert back all captured blocks + // revert back all captured blocks
+ world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710
+ for (BlockState blockstate : blocks) { + for (BlockState blockstate : blocks) {
+ blockstate.update(true, false); + blockstate.update(true, false);
+ } + }
+ world.preventPoiUpdated = false;
+ +
+ // Brute force all possible updates + // Brute force all possible updates
+ BlockPosition placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition(); + BlockPosition placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition();
@ -258,7 +260,7 @@
return enuminteractionresult; return enuminteractionresult;
} }
@@ -290,6 +483,21 @@ @@ -290,6 +485,21 @@
} }
i -= k; i -= k;
@ -280,7 +282,7 @@
if (i <= 0) { if (i <= 0) {
return false; return false;
} }
@@ -311,6 +519,11 @@ @@ -311,6 +521,11 @@
if (this.isDamaged(i, t0.getRandom(), t0 instanceof EntityPlayer ? (EntityPlayer) t0 : null)) { if (this.isDamaged(i, t0.getRandom(), t0 instanceof EntityPlayer ? (EntityPlayer) t0 : null)) {
consumer.accept(t0); consumer.accept(t0);
Item item = this.getItem(); Item item = this.getItem();
@ -292,7 +294,7 @@
this.subtract(1); this.subtract(1);
if (t0 instanceof EntityHuman) { if (t0 instanceof EntityHuman) {
@@ -466,6 +679,17 @@ @@ -466,6 +681,17 @@
return this.tag; return this.tag;
} }
@ -310,7 +312,7 @@
public NBTTagCompound getOrCreateTag() { public NBTTagCompound getOrCreateTag() {
if (this.tag == null) { if (this.tag == null) {
this.setTag(new NBTTagCompound()); this.setTag(new NBTTagCompound());
@@ -849,6 +1073,12 @@ @@ -849,6 +1075,12 @@
} }
public void setRepairCost(int i) { public void setRepairCost(int i) {
@ -323,7 +325,7 @@
this.getOrCreateTag().setInt("RepairCost", i); this.getOrCreateTag().setInt("RepairCost", i);
} }
@@ -898,6 +1128,13 @@ @@ -898,6 +1130,13 @@
nbttaglist.add(nbttagcompound); nbttaglist.add(nbttagcompound);
} }

View File

@ -29,7 +29,7 @@
public abstract class World implements GeneratorAccess, AutoCloseable { public abstract class World implements GeneratorAccess, AutoCloseable {
protected static final Logger LOGGER = LogManager.getLogger(); protected static final Logger LOGGER = LogManager.getLogger();
@@ -103,7 +125,49 @@ @@ -103,7 +125,50 @@
private final BiomeManager biomeManager; private final BiomeManager biomeManager;
private final ResourceKey<World> dimension; private final ResourceKey<World> dimension;
@ -41,6 +41,7 @@
+ public boolean keepSpawnInMemory = true; + public boolean keepSpawnInMemory = true;
+ public org.bukkit.generator.ChunkGenerator generator; + public org.bukkit.generator.ChunkGenerator generator;
+ +
+ public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710
+ public boolean captureBlockStates = false; + public boolean captureBlockStates = false;
+ public boolean captureTreeGeneration = false; + public boolean captureTreeGeneration = false;
+ public Map<BlockPosition, CapturedBlockState> capturedBlockStates = new java.util.LinkedHashMap<>(); + public Map<BlockPosition, CapturedBlockState> capturedBlockStates = new java.util.LinkedHashMap<>();
@ -80,7 +81,7 @@
this.profiler = supplier; this.profiler = supplier;
this.levelData = worlddatamutable; this.levelData = worlddatamutable;
this.dimensionType = dimensionmanager; this.dimensionType = dimensionmanager;
@@ -113,12 +177,12 @@ @@ -113,12 +178,12 @@
this.worldBorder = new WorldBorder() { this.worldBorder = new WorldBorder() {
@Override @Override
public double getCenterX() { public double getCenterX() {
@ -95,7 +96,7 @@
} }
}; };
} else { } else {
@@ -128,6 +192,35 @@ @@ -128,6 +193,35 @@
this.thread = Thread.currentThread(); this.thread = Thread.currentThread();
this.biomeManager = new BiomeManager(this, i, dimensionmanager.getGenLayerZoomer()); this.biomeManager = new BiomeManager(this, i, dimensionmanager.getGenLayerZoomer());
this.isDebug = flag1; this.isDebug = flag1;
@ -131,7 +132,7 @@
} }
@Override @Override
@@ -185,6 +278,17 @@ @@ -185,6 +279,17 @@
@Override @Override
public boolean a(BlockPosition blockposition, IBlockData iblockdata, int i, int j) { public boolean a(BlockPosition blockposition, IBlockData iblockdata, int i, int j) {
@ -149,7 +150,7 @@
if (this.isOutsideWorld(blockposition)) { if (this.isOutsideWorld(blockposition)) {
return false; return false;
} else if (!this.isClientSide && this.isDebugWorld()) { } else if (!this.isClientSide && this.isDebugWorld()) {
@@ -192,9 +296,24 @@ @@ -192,9 +297,24 @@
} else { } else {
Chunk chunk = this.getChunkAtWorldCoords(blockposition); Chunk chunk = this.getChunkAtWorldCoords(blockposition);
Block block = iblockdata.getBlock(); Block block = iblockdata.getBlock();
@ -175,7 +176,7 @@
return false; return false;
} else { } else {
IBlockData iblockdata2 = this.getType(blockposition); IBlockData iblockdata2 = this.getType(blockposition);
@@ -205,6 +324,7 @@ @@ -205,6 +325,7 @@
this.getMethodProfiler().exit(); this.getMethodProfiler().exit();
} }
@ -183,7 +184,7 @@
if (iblockdata2 == iblockdata) { if (iblockdata2 == iblockdata) {
if (iblockdata1 != iblockdata2) { if (iblockdata1 != iblockdata2) {
this.b(blockposition, iblockdata1, iblockdata2); this.b(blockposition, iblockdata1, iblockdata2);
@@ -231,12 +351,65 @@ @@ -231,12 +352,69 @@
this.a(blockposition, iblockdata1, iblockdata2); this.a(blockposition, iblockdata1, iblockdata2);
} }
@ -241,15 +242,19 @@
+ iblockdata.b(this, blockposition, k, j - 1); + iblockdata.b(this, blockposition, k, j - 1);
+ } + }
+ +
+ // CraftBukkit start - SPIGOT-5710
+ if (!preventPoiUpdated) {
+ this.a(blockposition, iblockdata1, iblockdata2); + this.a(blockposition, iblockdata1, iblockdata2);
+ } + }
+ // CraftBukkit end
+ }
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+ +
public void a(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {} public void a(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {}
@Override @Override
@@ -326,6 +499,17 @@ @@ -326,6 +504,17 @@
IBlockData iblockdata = this.getType(blockposition); IBlockData iblockdata = this.getType(blockposition);
try { try {
@ -267,7 +272,7 @@
iblockdata.doPhysics(this, blockposition, block, blockposition1, false); iblockdata.doPhysics(this, blockposition, block, blockposition1, false);
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Exception while updating neighbours"); CrashReport crashreport = CrashReport.a(throwable, "Exception while updating neighbours");
@@ -368,6 +552,14 @@ @@ -368,6 +557,14 @@
@Override @Override
public IBlockData getType(BlockPosition blockposition) { public IBlockData getType(BlockPosition blockposition) {
@ -282,7 +287,7 @@
if (this.isOutsideWorld(blockposition)) { if (this.isOutsideWorld(blockposition)) {
return Blocks.VOID_AIR.getBlockData(); return Blocks.VOID_AIR.getBlockData();
} else { } else {
@@ -484,7 +676,17 @@ @@ -484,7 +681,17 @@
@Nullable @Nullable
@Override @Override
@ -300,7 +305,7 @@
return this.isOutsideWorld(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAtWorldCoords(blockposition).a(blockposition, Chunk.EnumTileEntityState.IMMEDIATE)); return this.isOutsideWorld(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAtWorldCoords(blockposition).a(blockposition, Chunk.EnumTileEntityState.IMMEDIATE));
} }
@@ -492,6 +694,12 @@ @@ -492,6 +699,12 @@
BlockPosition blockposition = tileentity.getPosition(); BlockPosition blockposition = tileentity.getPosition();
if (!this.isOutsideWorld(blockposition)) { if (!this.isOutsideWorld(blockposition)) {
@ -313,7 +318,7 @@
this.getChunkAtWorldCoords(blockposition).b(tileentity); this.getChunkAtWorldCoords(blockposition).b(tileentity);
} }
} }
@@ -595,7 +803,7 @@ @@ -595,7 +808,7 @@
for (int j = 0; j < i; ++j) { for (int j = 0; j < i; ++j) {
EntityComplexPart entitycomplexpart = aentitycomplexpart[j]; EntityComplexPart entitycomplexpart = aentitycomplexpart[j];
@ -322,7 +327,7 @@
if (t0 != null && predicate.test(t0)) { if (t0 != null && predicate.test(t0)) {
list.add(t0); list.add(t0);
@@ -921,6 +1129,14 @@ @@ -921,6 +1134,14 @@
public abstract LevelEntityGetter<Entity> getEntities(); public abstract LevelEntityGetter<Entity> getEntities();
protected void a(@Nullable Entity entity, GameEvent gameevent, BlockPosition blockposition, int i) { protected void a(@Nullable Entity entity, GameEvent gameevent, BlockPosition blockposition, int i) {