AutoSerializeNBT and CapHolder

This commit is contained in:
Shadowfacts 2016-06-17 12:30:15 -04:00
parent 5eb211828a
commit e8b1439157
1 changed files with 6 additions and 18 deletions

View File

@ -6,14 +6,15 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable; import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.shadowfacts.shadowmc.ShadowMC; import net.shadowfacts.shadowmc.ShadowMC;
import net.shadowfacts.shadowmc.capability.CapHolder;
import net.shadowfacts.shadowmc.fluid.FluidTank;
import net.shadowfacts.shadowmc.nbt.AutoSerializeNBT;
import net.shadowfacts.shadowmc.network.PacketUpdateTE; import net.shadowfacts.shadowmc.network.PacketUpdateTE;
import net.shadowfacts.shadowmc.tileentity.BaseTileEntity; import net.shadowfacts.shadowmc.tileentity.BaseTileEntity;
@ -22,11 +23,13 @@ import net.shadowfacts.shadowmc.tileentity.BaseTileEntity;
*/ */
public class TileEntityFunnel extends BaseTileEntity implements ITickable { public class TileEntityFunnel extends BaseTileEntity implements ITickable {
@AutoSerializeNBT
@CapHolder(capabilities = IFluidHandler.class)
FluidTank tank = new FluidTank(FunnelsConfig.size); FluidTank tank = new FluidTank(FunnelsConfig.size);
private int tick; private int tick;
private void save() { void save() {
markDirty(); markDirty();
ShadowMC.network.sendToAllAround(new PacketUpdateTE(this), new NetworkRegistry.TargetPoint(worldObj.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64)); ShadowMC.network.sendToAllAround(new PacketUpdateTE(this), new NetworkRegistry.TargetPoint(worldObj.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64));
} }
@ -107,19 +110,4 @@ public class TileEntityFunnel extends BaseTileEntity implements ITickable {
return tag; return tag;
} }
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
}
@Override
@SuppressWarnings("unchecked")
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return (T)tank;
} else {
return super.getCapability(capability, facing);
}
}
} }