Protect BlockSnapshot and Chunk.getTileEntity from mutible BlockPos instances. Closes #2438
This commit is contained in:
parent
70fe18c163
commit
06130912c5
3 changed files with 40 additions and 4 deletions
32
patches/minecraft/net/minecraft/util/BlockPos.java.patch
Normal file
32
patches/minecraft/net/minecraft/util/BlockPos.java.patch
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
--- ../src-base/minecraft/net/minecraft/util/BlockPos.java
|
||||||
|
+++ ../src-work/minecraft/net/minecraft/util/BlockPos.java
|
||||||
|
@@ -257,6 +257,21 @@
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
+ /**
|
||||||
|
+ * Returns a version of this BlockPos that is guaranteed to be Immutable.
|
||||||
|
+ * In most cases this will return 'this', but if 'this' is an instance of
|
||||||
|
+ * MutableBlockPos it will return a new instance of BlockPos with the same values.
|
||||||
|
+ *
|
||||||
|
+ * When storing a parameter given to you for an extended period of time, make sure you
|
||||||
|
+ * use this in case the value is changed internally.
|
||||||
|
+ *
|
||||||
|
+ * @return An immutable BlockPos.
|
||||||
|
+ */
|
||||||
|
+ public BlockPos getImmutable()
|
||||||
|
+ {
|
||||||
|
+ return this;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
public static final class MutableBlockPos extends BlockPos
|
||||||
|
{
|
||||||
|
private int field_177997_b;
|
||||||
|
@@ -298,5 +313,7 @@
|
||||||
|
this.field_177996_d = p_181079_3_;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ @Override public BlockPos getImmutable() { return new BlockPos(this); }
|
||||||
|
}
|
||||||
|
}
|
|
@ -118,8 +118,12 @@
|
||||||
if (tileentity == null)
|
if (tileentity == null)
|
||||||
{
|
{
|
||||||
if (p_177424_2_ == Chunk.EnumCreateEntityType.IMMEDIATE)
|
if (p_177424_2_ == Chunk.EnumCreateEntityType.IMMEDIATE)
|
||||||
@@ -849,11 +852,6 @@
|
@@ -846,14 +849,9 @@
|
||||||
this.field_177447_w.add(p_177424_1_);
|
}
|
||||||
|
else if (p_177424_2_ == Chunk.EnumCreateEntityType.QUEUED)
|
||||||
|
{
|
||||||
|
- this.field_177447_w.add(p_177424_1_);
|
||||||
|
+ this.field_177447_w.add(p_177424_1_.getImmutable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
- else if (tileentity.func_145837_r())
|
- else if (tileentity.func_145837_r())
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class BlockSnapshot implements Serializable
|
||||||
{
|
{
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.dimId = world.provider.getDimensionId();
|
this.dimId = world.provider.getDimensionId();
|
||||||
this.pos = pos;
|
this.pos = pos.getImmutable();
|
||||||
this.replacedBlock = state;
|
this.replacedBlock = state;
|
||||||
this.blockIdentifier = GameRegistry.findUniqueIdentifierFor(state.getBlock());
|
this.blockIdentifier = GameRegistry.findUniqueIdentifierFor(state.getBlock());
|
||||||
this.meta = state.getBlock().getMetaFromState(state);
|
this.meta = state.getBlock().getMetaFromState(state);
|
||||||
|
@ -82,7 +82,7 @@ public class BlockSnapshot implements Serializable
|
||||||
public BlockSnapshot(int dimension, BlockPos pos, String modid, String blockName, int meta, int flag, NBTTagCompound nbt)
|
public BlockSnapshot(int dimension, BlockPos pos, String modid, String blockName, int meta, int flag, NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
this.dimId = dimension;
|
this.dimId = dimension;
|
||||||
this.pos = pos;
|
this.pos = pos.getImmutable();
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
this.blockIdentifier = new UniqueIdentifier(modid + ":" + blockName);
|
this.blockIdentifier = new UniqueIdentifier(modid + ":" + blockName);
|
||||||
this.meta = meta;
|
this.meta = meta;
|
||||||
|
|
Loading…
Reference in a new issue