mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 23:10:16 +01:00
SPIGOT-5123: Snapshot tile entities can end up with a non-null world
This commit is contained in:
parent
491c848210
commit
5815136865
3 changed files with 8 additions and 31 deletions
|
@ -34,7 +34,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
|
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
|
||||||
@@ -53,12 +70,24 @@
|
@@ -53,6 +70,11 @@
|
||||||
nbttagcompound.setInt("x", this.position.getX());
|
nbttagcompound.setInt("x", this.position.getX());
|
||||||
nbttagcompound.setInt("y", this.position.getY());
|
nbttagcompound.setInt("y", this.position.getY());
|
||||||
nbttagcompound.setInt("z", this.position.getZ());
|
nbttagcompound.setInt("z", this.position.getZ());
|
||||||
|
@ -46,28 +46,7 @@
|
||||||
return nbttagcompound;
|
return nbttagcompound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -168,4 +190,13 @@
|
||||||
+ // CraftBukkit start
|
|
||||||
@Nullable
|
|
||||||
public static TileEntity create(NBTTagCompound nbttagcompound) {
|
|
||||||
+ return create(nbttagcompound, null);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ @Nullable
|
|
||||||
+ public static TileEntity create(NBTTagCompound nbttagcompound, @Nullable World world) {
|
|
||||||
+ // CraftBukkit end
|
|
||||||
String s = nbttagcompound.getString("id");
|
|
||||||
|
|
||||||
return (TileEntity) IRegistry.BLOCK_ENTITY_TYPE.getOptional(new MinecraftKey(s)).map((tileentitytypes) -> {
|
|
||||||
@@ -70,6 +99,7 @@
|
|
||||||
}
|
|
||||||
}).map((tileentity) -> {
|
|
||||||
try {
|
|
||||||
+ tileentity.setWorld(world); // CraftBukkit
|
|
||||||
tileentity.load(nbttagcompound);
|
|
||||||
return tileentity;
|
|
||||||
} catch (Throwable throwable) {
|
|
||||||
@@ -168,4 +198,13 @@
|
|
||||||
}, this::getPosition});
|
}, this::getPosition});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.block;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.minecraft.server.BlockBannerAbstract;
|
||||||
import net.minecraft.server.EnumColor;
|
import net.minecraft.server.EnumColor;
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
import net.minecraft.server.NBTTagList;
|
import net.minecraft.server.NBTTagList;
|
||||||
|
@ -31,9 +32,7 @@ public class CraftBanner extends CraftBlockEntityState<TileEntityBanner> impleme
|
||||||
public void load(TileEntityBanner banner) {
|
public void load(TileEntityBanner banner) {
|
||||||
super.load(banner);
|
super.load(banner);
|
||||||
|
|
||||||
if (banner.color != null) {
|
base = DyeColor.getByWoolData((byte) ((BlockBannerAbstract) this.data.getBlock()).b().getColorIndex()); // PAIL
|
||||||
base = DyeColor.getByWoolData((byte) banner.color.getColorIndex());
|
|
||||||
}
|
|
||||||
patterns = new ArrayList<Pattern>();
|
patterns = new ArrayList<Pattern>();
|
||||||
|
|
||||||
if (banner.patterns != null) {
|
if (banner.patterns != null) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
|
||||||
import net.minecraft.server.BlockPosition;
|
import net.minecraft.server.BlockPosition;
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
import net.minecraft.server.TileEntity;
|
import net.minecraft.server.TileEntity;
|
||||||
import net.minecraft.server.World;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.TileState;
|
import org.bukkit.block.TileState;
|
||||||
|
@ -28,7 +27,7 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
|
||||||
Preconditions.checkState(this.tileEntity != null, "Tile is null, asynchronous access? " + block);
|
Preconditions.checkState(this.tileEntity != null, "Tile is null, asynchronous access? " + block);
|
||||||
|
|
||||||
// copy tile entity data:
|
// copy tile entity data:
|
||||||
this.snapshot = this.createSnapshot(tileEntity, world.getHandle());
|
this.snapshot = this.createSnapshot(tileEntity);
|
||||||
this.load(snapshot);
|
this.load(snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,17 +38,17 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
|
||||||
this.tileEntity = tileEntity;
|
this.tileEntity = tileEntity;
|
||||||
|
|
||||||
// copy tile entity data:
|
// copy tile entity data:
|
||||||
this.snapshot = this.createSnapshot(tileEntity, null);
|
this.snapshot = this.createSnapshot(tileEntity);
|
||||||
this.load(snapshot);
|
this.load(snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T createSnapshot(T tileEntity, World world) {
|
private T createSnapshot(T tileEntity) {
|
||||||
if (tileEntity == null) {
|
if (tileEntity == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTTagCompound nbtTagCompound = tileEntity.save(new NBTTagCompound());
|
NBTTagCompound nbtTagCompound = tileEntity.save(new NBTTagCompound());
|
||||||
T snapshot = (T) TileEntity.create(nbtTagCompound, world);
|
T snapshot = (T) TileEntity.create(nbtTagCompound);
|
||||||
|
|
||||||
return snapshot;
|
return snapshot;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue