Protect BlockSnapshot and Chunk.getTileEntity from mutible BlockPos instances. Closes #2438

This commit is contained in:
LexManos 2016-02-11 16:48:32 -08:00
parent 70fe18c163
commit 06130912c5
3 changed files with 40 additions and 4 deletions

View 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); }
}
}

View file

@ -118,8 +118,12 @@
if (tileentity == null)
{
if (p_177424_2_ == Chunk.EnumCreateEntityType.IMMEDIATE)
@@ -849,11 +852,6 @@
this.field_177447_w.add(p_177424_1_);
@@ -846,14 +849,9 @@
}
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())

View file

@ -58,7 +58,7 @@ public class BlockSnapshot implements Serializable
{
this.world = world;
this.dimId = world.provider.getDimensionId();
this.pos = pos;
this.pos = pos.getImmutable();
this.replacedBlock = state;
this.blockIdentifier = GameRegistry.findUniqueIdentifierFor(state.getBlock());
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)
{
this.dimId = dimension;
this.pos = pos;
this.pos = pos.getImmutable();
this.flag = flag;
this.blockIdentifier = new UniqueIdentifier(modid + ":" + blockName);
this.meta = meta;