package me.nallar.patched;

import me.nallar.tickthreading.patcher.Declare;
import me.nallar.tickthreading.util.concurrent.NativeMutex;
import me.nallar.tickthreading.util.concurrent.NotReallyAMutex;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInvBasic;
import net.minecraft.inventory.IInventory;
import net.minecraft.server.management.PlayerInstance;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.WorldServer;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;

public abstract class PatchTileEntity extends TileEntity {
	@Declare
	public int lastTTX_;
	@Declare
	public int lastTTY_;
	@Declare
	public int lastTTZ_;
	@Declare
	public me.nallar.tickthreading.minecraft.tickregion.TileEntityTickRegion tickRegion_;
	@Declare
	public java.util.concurrent.locks.Lock thisLock_;
	@Declare
	public java.util.concurrent.locks.Lock xMinusLock_;
	@Declare
	public java.util.concurrent.locks.Lock zMinusLock_;
	@Declare
	public java.util.concurrent.locks.Lock xPlusLock_;
	@Declare
	public java.util.concurrent.locks.Lock zPlusLock_;

	public void construct() {
		if (this instanceof IInventory || this instanceof ILiquidTank || this instanceof ICrafting || this instanceof IInvBasic || this instanceof ITankContainer) {
			thisLock = new NativeMutex();
		} else {
			thisLock = NotReallyAMutex.lock;
		}
	}

	@Override
	@Declare
	public void sendTileWithNotify() {
		WorldServer worldServer = ((WorldServer) worldObj);
		worldServer.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType().blockID);
		PlayerInstance p = worldServer.getPlayerManager().getOrCreateChunkWatcher(xCoord >> 4, zCoord >> 4, false);
		if (p != null) {
			p.updateTile(this);
		}
	}

	@Override
	@Declare
	public void sendTile() {
		PlayerInstance p = ((WorldServer) worldObj).getPlayerManager().getOrCreateChunkWatcher(xCoord >> 4, zCoord >> 4, false);
		if (p != null) {
			p.updateTile(this);
		}
	}
}

@@ -1552,16 +1552,63 @@
 dObj);%0D%0A
+%09%09if (worldServer == null) %7B%0D%0A%09%09%09return;%0D%0A%09%09%7D%0D%0A
 %09%09worldS

Fix #449