package info.u_team.u_team_test.tileentity;

import info.u_team.u_team_core.inventory.*;
import info.u_team.u_team_core.tileentity.UTickableTileEntity;
import info.u_team.u_team_test.init.TestTileEntityTypes;
import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.common.util.LazyOptional;

public class BasicFluidInventoryTileEntity extends UTickableTileEntity {
	
	protected final UItemStackHandler itemSlots;
	protected final LazyOptional<UItemStackHandler> itemSlotsOptional;
	
	protected final UFluidStackHandler fluidTanks;
	protected final LazyOptional<UFluidStackHandler> fluidTanksOptional;
	
	public BasicFluidInventoryTileEntity() {
		super(TestTileEntityTypes.BASIC_FLUID_INVENTORY);
		
		itemSlots = new TileEntityUItemStackHandler(4, this);
		itemSlotsOptional = LazyOptional.of(() -> itemSlots);
		
		fluidTanks = new UFluidStackHandler(4); // TODO tile entity u fluid stack handler
		fluidTanksOptional = LazyOptional.of(() -> fluidTanks);
	}
	
	@Override
	public void writeNBT(CompoundNBT compound) {
		super.writeNBT(compound);
		compound.put("items", itemSlots.serializeNBT());
		compound.put("fluids", fluidTanks.serializeNBT());
	}
	
	@Override
	public void readNBT(CompoundNBT compound) {
		super.readNBT(compound);
		itemSlots.deserializeNBT(compound.getCompound("items"));
		fluidTanks.deserializeNBT(compound.getCompound("fluids"));
	}
	
	@Override
	public void remove() {
		super.remove();
		itemSlotsOptional.invalidate();
		fluidTanksOptional.invalidate();
	}
	
	public UItemStackHandler getItemSlots() {
		return itemSlots;
	}
	
	public UFluidStackHandler getFluidTanks() {
		return fluidTanks;
	}
	
}

@@ -264,38 +264,307 @@
 raft
-forge.common.util.LazyOptional
+.util.Direction;%0Aimport net.minecraftforge.common.capabilities.Capability;%0Aimport net.minecraftforge.common.util.LazyOptional;%0Aimport net.minecraftforge.energy.CapabilityEnergy;%0Aimport net.minecraftforge.fluids.capability.CapabilityFluidHandler;%0Aimport net.minecraftforge.items.CapabilityItemHandler
 ;%0A%0Ap
@@ -1900,10 +1900,411 @@
 s;%0A%09%7D%0A%09%0A
+%09// Capability%0A%09@Override%0A%09public %3CX%3E LazyOptional%3CX%3E getCapability(Capability%3CX%3E capability, Direction side) %7B%0A%09%09if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) %7B%0A%09%09%09return itemSlotsOptional.cast();%0A%09%09%7D else if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) %7B%0A%09%09%09return fluidTanksOptional.cast();%0A%09%09%7D else %7B%0A%09%09%09return super.getCapability(capability, side);%0A%09%09%7D%0A%09%7D%0A%09%0A
 %7D%0A

Add capability