// Path: src/java/cd4017be/kineng/capability/StructureLocations.java
// @CapabilityInject(StructureLocations.class)
// public static final Capability<StructureLocations> MULTIBLOCKS = null;
// 
// Path: src/java/cd4017be/kineng/capability/StructureLocations.java
// public class Entry implements Iterator<Entry>, Iterable<Entry> {
// 
// 	private final BlockPos pos;
// 	private final int k;
// 	private int i = 0, c, p0, s;
// 
// 	private Entry(BlockPos pos, int id) {
// 		this.pos = pos;
// 		this.k = 0x4020100 | id << 27
// 			| (pos.getX() & 0xff)
// 			| (pos.getY() & 0xff) << 9
// 			| (pos.getZ() & 0xff) << 18;
// 	}
// 
// 	@Override
// 	public boolean hasNext() {
// 		int[] str = structures;
// 		int i = this.i, n = count;
// 		for (int k = this.k;
// 			i < n && ((k - str[i+1] | 0x4020100) - str[i+2] & 0xfc020100) != 0;
// 		i+=3);
// 		return (this.i = i) < n;
// 	}
// 
// 	@Override
// 	public Entry next() {
// 		int[] str = structures;
// 		int i = this.i;
// 		c = str[i];
// 		p0 = str[i+1];
// 		s = str[i+2];
// 		this.i = i + 3;
// 		return this;
// 	}
// 
// 	public BlockPos core() {
// 		return new BlockPos(
// 			x0() + (c - p0 & 0xff), c >> 9 & 0xff,
// 			z0() + ((c >> 18) - (p0 >> 18) & 0xff)
// 		);
// 	}
// 
// 	public final int x0() {
// 		int x = p0 & 0xff;
// 		return pos.getX() - x & 0xffffff00 | x;
// 	}
// 	public final int y0() {
// 		return p0 >> 9 & 0xff;
// 	}
// 	public final int z0() {
// 		int z = p0 >> 18 & 0xff;
// 		return pos.getZ() - z & 0xffffff00 | z;
// 	}
// 	public final int sx() {return s       & 0xff;}
// 	public final int sy() {return s >>  9 & 0xff;}
// 	public final int sz() {return s >> 18 & 0xff;}
// 	public final int x1() {return x0() + sx();}
// 	public final int y1() {return y0() + sy();}
// 	public final int z1() {return z0() + sz();}
// 
// 	@Override
// 	public Iterator<Entry> iterator() {
// 		return this;
// 	}
// }


import static cd4017be.kineng.capability.StructureLocations.MULTIBLOCKS;
import java.util.List;
import cd4017be.kineng.capability.StructureLocations.Entry;
import cd4017be.lib.block.AdvancedBlock.ITilePlaceHarvest;
import cd4017be.lib.tileentity.BaseTileEntity;
import cd4017be.lib.tileentity.BaseTileEntity.ITickableServerOnly;
import cd4017be.lib.util.Utils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;

package cd4017be.kineng.tileentity;



/** 
 * @author CD4017BE */
public abstract class LakeConnection extends BaseTileEntity
implements ITickableServerOnly, ITilePlaceHarvest {

	protected BlockPos core;
	protected StorageLake lake;

	@Override
	public void update() {
		if (lake != null && !lake.invalid() || getLake())
			tickLakeInteract();
	}

	protected abstract void tickLakeInteract();

	protected float relLiquidLvl() {
		return (float)(core.getY() - pos.getY() + (lake.level >> 1)) + lake.partLevel();
	}

	protected boolean getLake() {
		if (core == null) return false;
		TileEntity te = Utils.getTileAt(world, core);
		if (te instanceof StorageLake) {
			lake = (StorageLake)te;
			return true;
		} else return false;
	}

	@Override
	public void onLoad() {
		super.onLoad();
		BlockPos pos = this.pos.offset(getOrientation().back);

// Path: src/java/cd4017be/kineng/capability/StructureLocations.java
// @CapabilityInject(StructureLocations.class)
// public static final Capability<StructureLocations> MULTIBLOCKS = null;
// 
// Path: src/java/cd4017be/kineng/capability/StructureLocations.java
// public class Entry implements Iterator<Entry>, Iterable<Entry> {
// 
// 	private final BlockPos pos;
// 	private final int k;
// 	private int i = 0, c, p0, s;
// 
// 	private Entry(BlockPos pos, int id) {
// 		this.pos = pos;
// 		this.k = 0x4020100 | id << 27
// 			| (pos.getX() & 0xff)
// 			| (pos.getY() & 0xff) << 9
// 			| (pos.getZ() & 0xff) << 18;
// 	}
// 
// 	@Override
// 	public boolean hasNext() {
// 		int[] str = structures;
// 		int i = this.i, n = count;
// 		for (int k = this.k;
// 			i < n && ((k - str[i+1] | 0x4020100) - str[i+2] & 0xfc020100) != 0;
// 		i+=3);
// 		return (this.i = i) < n;
// 	}
// 
// 	@Override
// 	public Entry next() {
// 		int[] str = structures;
// 		int i = this.i;
// 		c = str[i];
// 		p0 = str[i+1];
// 		s = str[i+2];
// 		this.i = i + 3;
// 		return this;
// 	}
// 
// 	public BlockPos core() {
// 		return new BlockPos(
// 			x0() + (c - p0 & 0xff), c >> 9 & 0xff,
// 			z0() + ((c >> 18) - (p0 >> 18) & 0xff)
// 		);
// 	}
// 
// 	public final int x0() {
// 		int x = p0 & 0xff;
// 		return pos.getX() - x & 0xffffff00 | x;
// 	}
// 	public final int y0() {
// 		return p0 >> 9 & 0xff;
// 	}
// 	public final int z0() {
// 		int z = p0 >> 18 & 0xff;
// 		return pos.getZ() - z & 0xffffff00 | z;
// 	}
// 	public final int sx() {return s       & 0xff;}
// 	public final int sy() {return s >>  9 & 0xff;}
// 	public final int sz() {return s >> 18 & 0xff;}
// 	public final int x1() {return x0() + sx();}
// 	public final int y1() {return y0() + sy();}
// 	public final int z1() {return z0() + sz();}
// 
// 	@Override
// 	public Iterator<Entry> iterator() {
// 		return this;
// 	}
// }


// Path: src/java/cd4017be/kineng/tileentity/LakeConnection.java
import static cd4017be.kineng.capability.StructureLocations.MULTIBLOCKS;
import java.util.List;
import cd4017be.kineng.capability.StructureLocations.Entry;
import cd4017be.lib.block.AdvancedBlock.ITilePlaceHarvest;
import cd4017be.lib.tileentity.BaseTileEntity;
import cd4017be.lib.tileentity.BaseTileEntity.ITickableServerOnly;
import cd4017be.lib.util.Utils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;

package cd4017be.kineng.tileentity;



/** 
 * @author CD4017BE */
public abstract class LakeConnection extends BaseTileEntity
implements ITickableServerOnly, ITilePlaceHarvest {

	protected BlockPos core;
	protected StorageLake lake;

	@Override
	public void update() {
		if (lake != null && !lake.invalid() || getLake())
			tickLakeInteract();
	}

	protected abstract void tickLakeInteract();

	protected float relLiquidLvl() {
		return (float)(core.getY() - pos.getY() + (lake.level >> 1)) + lake.partLevel();
	}

	protected boolean getLake() {
		if (core == null) return false;
		TileEntity te = Utils.getTileAt(world, core);
		if (te instanceof StorageLake) {
			lake = (StorageLake)te;
			return true;
		} else return false;
	}

	@Override
	public void onLoad() {
		super.onLoad();
		BlockPos pos = this.pos.offset(getOrientation().back);

		for (Entry e : getChunk().getCapability(MULTIBLOCKS, null).find(pos, 0)) {
