use of tonius.simplyjetpacks.setup.FuelType in project SimplyJetpacks by Tonius.
the class ItemJetpackFueller method onUsingTick.
@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
if (blockPos == null || blockPos.sideHit < 0) {
player.setItemInUse(null, 1);
} else {
player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
if (player.worldObj.isRemote) {
return;
}
ItemStack chestplate = player.getCurrentArmor(2);
if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
return;
}
ItemPack packItem = (ItemPack) chestplate.getItem();
PackBase pack = packItem.getPack(chestplate);
if (pack == null) {
return;
}
FuelType fuelType = pack.fuelType;
ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
int pulled = 0;
if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
IEnergyProvider energyTile = (IEnergyProvider) tile;
pulled = energyTile.extractEnergy(pullSide, toPull, false);
} else if (fuelType == FuelType.FLUID) {
if (tile instanceof IFluidHandler) {
IFluidHandler fluidTile = (IFluidHandler) tile;
FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
return;
}
fluid = fluidTile.drain(pullSide, toPull, true);
pulled = fluid.amount;
}
}
if (pulled > 0) {
packItem.addFuel(chestplate, pulled, false);
}
}
}
Aggregations