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.IInventory;
import net.minecraft.server.management.PlayerInstance;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.WorldServer;
import net.minecraftforge.liquids.ILiquidTank;

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

@@ -194,24 +194,110 @@
 llyAMutex;%0D%0A
+import net.minecraft.inventory.ICrafting;%0D%0Aimport net.minecraft.inventory.IInvBasic;%0D%0A
 import net.m
@@ -517,16 +517,67 @@
 idTank;%0D
+%0Aimport net.minecraftforge.liquids.ITankContainer;%0D
 %0A%0D%0Apubli
@@ -1246,16 +1246,108 @@
 quidTank
+ %7C%7C this instanceof ICrafting %7C%7C this instanceof IInvBasic %7C%7C this instanceof ITankContainer
 ) %7B%0D%0A%09%09%09

Add more interfaces which require locking