Files
MinecraftForge/patches/minecraft/net/minecraft/world/chunk/Chunk.java.patch
T

324 lines
13 KiB
Diff

--- ../src-base/minecraft/net/minecraft/world/chunk/Chunk.java
+++ ../src-work/minecraft/net/minecraft/world/chunk/Chunk.java
@@ -29,6 +29,10 @@
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.WorldChunkManager;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.entity.EntityEvent;
+import net.minecraftforge.event.world.ChunkEvent;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -194,7 +198,7 @@
{
Block block = this.func_150810_a(j, l - 1, k);
- if (block.func_149717_k() == 0)
+ if (func_150808_b(j, l - 1, k) == 0)
{
--l;
continue;
@@ -493,7 +497,9 @@
public int func_150808_b(int p_150808_1_, int p_150808_2_, int p_150808_3_)
{
- return this.func_150810_a(p_150808_1_, p_150808_2_, p_150808_3_).func_149717_k();
+ int x = (field_76635_g << 4) + p_150808_1_;
+ int z = (field_76647_h << 4) + p_150808_3_;
+ return this.func_150810_a(p_150808_1_, p_150808_2_, p_150808_3_).getLightOpacity(field_76637_e, x, p_150808_2_, z);
}
public Block func_150810_a(final int p_150810_1_, final int p_150810_2_, final int p_150810_3_)
@@ -579,20 +585,33 @@
int l1 = this.field_76635_g * 16 + p_150807_1_;
int i2 = this.field_76647_h * 16 + p_150807_3_;
+ int k2 = block1.getLightOpacity(this.field_76637_e, l1, p_150807_2_, i2);
+
if (!this.field_76637_e.field_72995_K)
{
block1.func_149725_f(this.field_76637_e, l1, p_150807_2_, i2, k1);
}
extendedblockstorage.func_150818_a(p_150807_1_, p_150807_2_ & 15, p_150807_3_, p_150807_4_);
+ extendedblockstorage.func_76654_b(p_150807_1_, p_150807_2_ & 15, p_150807_3_, p_150807_5_); // This line duplicates the one below, so breakBlock fires with valid worldstate
if (!this.field_76637_e.field_72995_K)
{
block1.func_149749_a(this.field_76637_e, l1, p_150807_2_, i2, block1, k1);
+ // After breakBlock a phantom TE might have been created with incorrect meta. This attempts to kill that phantom TE so the normal one can be create properly later
+ TileEntity te = this.getTileEntityUnsafe(p_150807_1_ & 0x0F, p_150807_2_, p_150807_3_ & 0x0F);
+ if (te != null && te.shouldRefresh(block1, func_150810_a(p_150807_1_ & 0x0F, p_150807_2_, p_150807_3_ & 0x0F), k1, func_76628_c(p_150807_1_ & 0x0F, p_150807_2_, p_150807_3_ & 0x0F), field_76637_e, l1, p_150807_2_, i2))
+ {
+ this.func_150805_f(p_150807_1_ & 0x0F, p_150807_2_, p_150807_3_ & 0x0F);
+ }
}
- else if (block1 instanceof ITileEntityProvider && block1 != p_150807_4_)
+ else if (block1.hasTileEntity(k1))
{
- this.field_76637_e.func_147475_p(l1, p_150807_2_, i2);
+ TileEntity te = this.getTileEntityUnsafe(p_150807_1_ & 0x0F, p_150807_2_, p_150807_3_ & 0x0F);
+ if (te != null && te.shouldRefresh(block1, p_150807_4_, k1, p_150807_5_, field_76637_e, l1, p_150807_2_, i2))
+ {
+ this.field_76637_e.func_147475_p(l1, p_150807_2_, i2);
+ }
}
if (extendedblockstorage.func_150819_a(p_150807_1_, p_150807_2_ & 15, p_150807_3_) != p_150807_4_)
@@ -609,8 +628,7 @@
}
else
{
- int j2 = p_150807_4_.func_149717_k();
- int k2 = block1.func_149717_k();
+ int j2 = p_150807_4_.getLightOpacity(this.field_76637_e, l1, p_150807_2_, i2);
if (j2 > 0)
{
@@ -632,34 +650,19 @@
TileEntity tileentity;
- if (block1 instanceof ITileEntityProvider)
- {
- tileentity = this.func_150806_e(p_150807_1_, p_150807_2_, p_150807_3_);
-
- if (tileentity != null)
- {
- tileentity.func_145836_u();
- }
- }
-
if (!this.field_76637_e.field_72995_K)
{
p_150807_4_.func_149726_b(this.field_76637_e, l1, p_150807_2_, i2);
}
- if (p_150807_4_ instanceof ITileEntityProvider)
+ if (p_150807_4_.hasTileEntity(p_150807_5_))
{
tileentity = this.func_150806_e(p_150807_1_, p_150807_2_, p_150807_3_);
- if (tileentity == null)
- {
- tileentity = ((ITileEntityProvider)p_150807_4_).func_149915_a(this.field_76637_e, p_150807_5_);
- this.field_76637_e.func_147455_a(l1, p_150807_2_, i2, tileentity);
- }
-
if (tileentity != null)
{
tileentity.func_145836_u();
+ tileentity.field_145847_g = p_150807_5_;
}
}
@@ -690,7 +693,7 @@
this.field_76643_l = true;
extendedblockstorage.func_76654_b(p_76589_1_, p_76589_2_ & 15, p_76589_3_, p_76589_4_);
- if (extendedblockstorage.func_150819_a(p_76589_1_, p_76589_2_ & 15, p_76589_3_) instanceof ITileEntityProvider)
+ if (extendedblockstorage.func_150819_a(p_76589_1_, p_76589_2_ & 15, p_76589_3_).hasTileEntity(p_76589_4_))
{
TileEntity tileentity = this.func_150806_e(p_76589_1_, p_76589_2_, p_76589_3_);
@@ -790,6 +793,7 @@
k = this.field_76645_j.length - 1;
}
+ MinecraftForge.EVENT_BUS.post(new EntityEvent.EnteringChunk(p_76612_1_, this.field_76635_g, this.field_76647_h, p_76612_1_.field_70176_ah, p_76612_1_.field_70164_aj));
p_76612_1_.field_70175_ag = true;
p_76612_1_.field_70176_ah = this.field_76635_g;
p_76612_1_.field_70162_ai = k;
@@ -827,28 +831,27 @@
ChunkPosition chunkposition = new ChunkPosition(p_150806_1_, p_150806_2_, p_150806_3_);
TileEntity tileentity = (TileEntity)this.field_150816_i.get(chunkposition);
+ if (tileentity != null && tileentity.func_145837_r())
+ {
+ field_150816_i.remove(chunkposition);
+ tileentity = null;
+ }
+
if (tileentity == null)
{
Block block = this.func_150810_a(p_150806_1_, p_150806_2_, p_150806_3_);
+ int meta = this.func_76628_c(p_150806_1_, p_150806_2_, p_150806_3_);
- if (!block.func_149716_u())
+ if (!block.hasTileEntity(meta))
{
return null;
}
- tileentity = ((ITileEntityProvider)block).func_149915_a(this.field_76637_e, this.func_76628_c(p_150806_1_, p_150806_2_, p_150806_3_));
+ tileentity = block.createTileEntity(field_76637_e, meta);
this.field_76637_e.func_147455_a(this.field_76635_g * 16 + p_150806_1_, p_150806_2_, this.field_76647_h * 16 + p_150806_3_, tileentity);
}
- if (tileentity != null && tileentity.func_145837_r())
- {
- this.field_150816_i.remove(chunkposition);
- return null;
- }
- else
- {
- return tileentity;
- }
+ return tileentity;
}
public void func_150813_a(TileEntity p_150813_1_)
@@ -860,7 +863,7 @@
if (this.field_76636_d)
{
- this.field_76637_e.field_147482_g.add(p_150813_1_);
+ this.field_76637_e.addTileEntity(p_150813_1_);
}
}
@@ -872,7 +875,8 @@
p_150812_4_.field_145848_d = p_150812_2_;
p_150812_4_.field_145849_e = this.field_76647_h * 16 + p_150812_3_;
- if (this.func_150810_a(p_150812_1_, p_150812_2_, p_150812_3_) instanceof ITileEntityProvider)
+ int metadata = func_76628_c(p_150812_1_, p_150812_2_, p_150812_3_);
+ if (this.func_150810_a(p_150812_1_, p_150812_2_, p_150812_3_).hasTileEntity(metadata))
{
if (this.field_150816_i.containsKey(chunkposition))
{
@@ -916,6 +920,7 @@
this.field_76637_e.func_72868_a(this.field_76645_j[i]);
}
+ MinecraftForge.EVENT_BUS.post(new ChunkEvent.Load(this));
}
public void func_76623_d()
@@ -933,6 +938,7 @@
{
this.field_76637_e.func_72828_b(this.field_76645_j[i]);
}
+ MinecraftForge.EVENT_BUS.post(new ChunkEvent.Unload(this));
}
public void func_76630_e()
@@ -942,8 +948,8 @@
public void func_76588_a(Entity p_76588_1_, AxisAlignedBB p_76588_2_, List p_76588_3_, IEntitySelector p_76588_4_)
{
- int i = MathHelper.func_76128_c((p_76588_2_.field_72338_b - 2.0D) / 16.0D);
- int j = MathHelper.func_76128_c((p_76588_2_.field_72337_e + 2.0D) / 16.0D);
+ int i = MathHelper.func_76128_c((p_76588_2_.field_72338_b - World.MAX_ENTITY_RADIUS) / 16.0D);
+ int j = MathHelper.func_76128_c((p_76588_2_.field_72337_e + World.MAX_ENTITY_RADIUS) / 16.0D);
i = MathHelper.func_76125_a(i, 0, this.field_76645_j.length - 1);
j = MathHelper.func_76125_a(j, 0, this.field_76645_j.length - 1);
@@ -979,8 +985,8 @@
public void func_76618_a(Class p_76618_1_, AxisAlignedBB p_76618_2_, List p_76618_3_, IEntitySelector p_76618_4_)
{
- int i = MathHelper.func_76128_c((p_76618_2_.field_72338_b - 2.0D) / 16.0D);
- int j = MathHelper.func_76128_c((p_76618_2_.field_72337_e + 2.0D) / 16.0D);
+ int i = MathHelper.func_76128_c((p_76618_2_.field_72338_b - World.MAX_ENTITY_RADIUS) / 16.0D);
+ int j = MathHelper.func_76128_c((p_76618_2_.field_72337_e + World.MAX_ENTITY_RADIUS) / 16.0D);
i = MathHelper.func_76125_a(i, 0, this.field_76645_j.length - 1);
j = MathHelper.func_76125_a(j, 0, this.field_76645_j.length - 1);
@@ -1139,6 +1145,15 @@
@SideOnly(Side.CLIENT)
public void func_76607_a(byte[] p_76607_1_, int p_76607_2_, int p_76607_3_, boolean p_76607_4_)
{
+ Iterator iterator = field_150816_i.values().iterator();
+ while(iterator.hasNext())
+ {
+ TileEntity tileEntity = (TileEntity)iterator.next();
+ tileEntity.func_145836_u();
+ tileEntity.func_145832_p();
+ tileEntity.func_145838_q();
+ }
+
int k = 0;
boolean flag1 = !this.field_76637_e.field_73011_w.field_76576_e;
int l;
@@ -1241,13 +1256,27 @@
this.field_150814_l = true;
this.field_76646_k = true;
this.func_76590_a();
- Iterator iterator = this.field_150816_i.values().iterator();
+ List<TileEntity> invalidList = new ArrayList<TileEntity>();
+ iterator = this.field_150816_i.values().iterator();
while (iterator.hasNext())
{
TileEntity tileentity = (TileEntity)iterator.next();
+ int x = tileentity.field_145851_c & 15;
+ int y = tileentity.field_145848_d;
+ int z = tileentity.field_145849_e & 15;
+ Block block = tileentity.func_145838_q();
+ if ((block != func_150810_a(x, y, z) || tileentity.field_145847_g != this.func_76628_c(x, y, z)) && tileentity.shouldRefresh(block, func_150810_a(x, y, z), tileentity.field_145847_g, this.func_76628_c(x, y, z), field_76637_e, x, y, z))
+ {
+ invalidList.add(tileentity);
+ }
tileentity.func_145836_u();
}
+
+ for (TileEntity te : invalidList)
+ {
+ te.func_145843_s();
+ }
}
public BiomeGenBase func_76591_a(int p_76591_1_, int p_76591_2_, WorldChunkManager p_76591_3_)
@@ -1450,4 +1479,48 @@
return true;
}
+
+ /**
+ * Retrieves the tile entity, WITHOUT creating it.
+ * Good for checking if it exists.
+ *
+ * @param x
+ * @param y
+ * @param z
+ * @return The tile entity at the specified location, if it exists and is valid.
+ */
+ public TileEntity getTileEntityUnsafe(int x, int y, int z)
+ {
+ ChunkPosition chunkposition = new ChunkPosition(x, y, z);
+ TileEntity tileentity = (TileEntity)this.field_150816_i.get(chunkposition);
+
+ if (tileentity != null && tileentity.func_145837_r())
+ {
+ field_150816_i.remove(chunkposition);
+ tileentity = null;
+ }
+
+ return tileentity;
+ }
+
+ /**
+ * Removes the tile entity at the specified position, only if it's
+ * marked as invalid.
+ *
+ * @param x
+ * @param y
+ * @param z
+ */
+ public void removeInvalidTileEntity(int x, int y, int z)
+ {
+ ChunkPosition position = new ChunkPosition(x, y, z);
+ if (field_76636_d)
+ {
+ TileEntity entity = (TileEntity)field_150816_i.get(position);
+ if (entity != null && entity.func_145837_r())
+ {
+ field_150816_i.remove(position);
+ }
+ }
+ }
}